diff options
| author | Vicent Martà <vicent@github.com> | 2013-06-17 08:53:22 -0700 |
|---|---|---|
| committer | Vicent Martà <vicent@github.com> | 2013-06-17 08:53:22 -0700 |
| commit | 705871364bce85f7ef46f7c3f4e680a4591aa304 (patch) | |
| tree | a9881790a595313daed76a6fc3deecedf3a1a069 | |
| parent | 824cf80f061ab31f45c94576f9e75533201a4578 (diff) | |
| parent | 0525fb7ef3cb347e20db8582dcfc9c4c67bd9267 (diff) | |
| download | libgit2-705871364bce85f7ef46f7c3f4e680a4591aa304.tar.gz | |
Merge pull request #1654 from yorah/memzero
Memzero stuffs
| -rw-r--r-- | src/transports/cred.c | 4 | ||||
| -rw-r--r-- | src/util.c | 9 | ||||
| -rw-r--r-- | src/util.h | 12 |
3 files changed, 13 insertions, 12 deletions
diff --git a/src/transports/cred.c b/src/transports/cred.c index 4916c6e18..ba5de6e93 100644 --- a/src/transports/cred.c +++ b/src/transports/cred.c @@ -17,7 +17,7 @@ static void plaintext_free(struct git_cred *cred) git__free(c->username); /* Zero the memory which previously held the password */ - memset(c->password, 0x0, pass_len); + git__memzero(c->password, pass_len); git__free(c->password); memset(c, 0, sizeof(*c)); @@ -73,7 +73,7 @@ static void ssh_keyfile_passphrase_free(struct git_cred *cred) if (c->passphrase) { /* Zero the memory which previously held the passphrase */ - memset(c->passphrase, 0x0, pass_len); + git__memzero(c->passphrase, pass_len); git__free(c->passphrase); } diff --git a/src/util.c b/src/util.c index 1d084daa8..da15a039d 100644 --- a/src/util.c +++ b/src/util.c @@ -722,12 +722,3 @@ void git__insertsort_r( if (freeswap) git__free(swapel); } - -void git__memzero(volatile void *data, size_t size) -{ - volatile uint8_t *scan = data; - uint8_t *end = scan + size; - - while (scan < end) - *scan++ = 0x0; -} diff --git a/src/util.h b/src/util.h index 0de466677..1ef9e65b5 100644 --- a/src/util.h +++ b/src/util.h @@ -325,6 +325,16 @@ extern size_t git__unescape(char *str); * Safely zero-out memory, making sure that the compiler * doesn't optimize away the operation. */ -extern void git__memzero(volatile void *data, size_t size); +GIT_INLINE(void) git__memzero(void *data, size_t size) +{ +#ifdef _MSC_VER + SecureZeroMemory((PVOID)data, size); +#else + volatile uint8_t *scan = (volatile uint8_t *)data; + + while (size--) + *scan++ = 0x0; +#endif +} #endif /* INCLUDE_util_h__ */ |
