mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 11:06:32 +00:00
str: provide a zero mechanism
We provide `git__memzero` but make a simple helper for `git_str_zero` that does the same.
This commit is contained in:
@@ -145,6 +145,14 @@ void git_str_clear(git_str *buf)
|
||||
buf->ptr[0] = '\0';
|
||||
}
|
||||
|
||||
void git_str_zero(git_str *buf)
|
||||
{
|
||||
if (buf->asize > 0)
|
||||
git__memzero(buf->ptr, buf->asize);
|
||||
|
||||
git_str_clear(buf);
|
||||
}
|
||||
|
||||
int git_str_set(git_str *buf, const void *data, size_t len)
|
||||
{
|
||||
size_t alloclen;
|
||||
|
||||
@@ -354,4 +354,12 @@ int git_str_is_binary(const git_str *str);
|
||||
*/
|
||||
int git_str_contains_nul(const git_str *str);
|
||||
|
||||
/**
|
||||
* Clears the given string buffer and overwrites it with zeros, to
|
||||
* prevent sensitive data from remaining in the heap.
|
||||
*
|
||||
* @param str string buffer to clear
|
||||
*/
|
||||
void git_str_zero(git_str *str);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user