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:
Edward Thomson
2024-12-12 14:02:14 +00:00
parent 6821bde736
commit c1ee11c262
2 changed files with 16 additions and 0 deletions

View File

@@ -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;

View File

@@ -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