diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gnutls.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/gnutls.c b/src/gnutls.c index e6f01a9cfe1..7d19f90fbb8 100644 --- a/src/gnutls.c +++ b/src/gnutls.c | |||
| @@ -1883,6 +1883,22 @@ The alist key is the cipher name. */) | |||
| 1883 | return ciphers; | 1883 | return ciphers; |
| 1884 | } | 1884 | } |
| 1885 | 1885 | ||
| 1886 | /* Zero out STORAGE (even if it will become inaccessible. It has | ||
| 1887 | STORAGE_LENGTH bytes. The goal is to improve security a bit, in | ||
| 1888 | case an Emacs module or some buggy part of Emacs attempts to | ||
| 1889 | inspect STORAGE later to retrieve a secret. | ||
| 1890 | |||
| 1891 | Calls to this function document when storage containing a secret is | ||
| 1892 | known to go out of scope. This function is not guaranteed to erase | ||
| 1893 | the secret, as copies of STORAGE may well be accessible elsewhere | ||
| 1894 | on the machine. */ | ||
| 1895 | |||
| 1896 | static void | ||
| 1897 | clear_storage (void *storage, ptrdiff_t storage_length) | ||
| 1898 | { | ||
| 1899 | explicit_bzero (storage, storage_length); | ||
| 1900 | } | ||
| 1901 | |||
| 1886 | static Lisp_Object | 1902 | static Lisp_Object |
| 1887 | gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, | 1903 | gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, |
| 1888 | Lisp_Object cipher, | 1904 | Lisp_Object cipher, |
| @@ -1949,7 +1965,7 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, | |||
| 1949 | 1965 | ||
| 1950 | if (ret < GNUTLS_E_SUCCESS) | 1966 | if (ret < GNUTLS_E_SUCCESS) |
| 1951 | { | 1967 | { |
| 1952 | memset (storage, 0, storage_length); | 1968 | clear_storage (storage, storage_length); |
| 1953 | SAFE_FREE (); | 1969 | SAFE_FREE (); |
| 1954 | gnutls_aead_cipher_deinit (acipher); | 1970 | gnutls_aead_cipher_deinit (acipher); |
| 1955 | if (encrypting) | 1971 | if (encrypting) |
| @@ -1963,7 +1979,7 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, | |||
| 1963 | gnutls_aead_cipher_deinit (acipher); | 1979 | gnutls_aead_cipher_deinit (acipher); |
| 1964 | 1980 | ||
| 1965 | Lisp_Object output = make_unibyte_string (storage, storage_length); | 1981 | Lisp_Object output = make_unibyte_string (storage, storage_length); |
| 1966 | memset (storage, 0, storage_length); | 1982 | clear_storage (storage, storage_length); |
| 1967 | SAFE_FREE (); | 1983 | SAFE_FREE (); |
| 1968 | return list2 (output, actual_iv); | 1984 | return list2 (output, actual_iv); |
| 1969 | #else | 1985 | #else |