diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-07-07 19:28:38 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2015-07-07 19:33:35 +0200 |
commit | b3fc17453bf586a99879a7bba03122a4f0b7aa6d (patch) | |
tree | ea40aec5783c5d1acddf6bf4c32bd4be049be4ea | |
parent | a9c15554de5dfb0f8565e8b50f40562f6ce4a816 (diff) | |
download | libgcrypt-b3fc17453bf586a99879a7bba03122a4f0b7aa6d.tar.gz |
Fix undefined behavior wrt memcpy
* cipher/cipher-gcm.c: Do not copy zero bytes from an empty buffer. Let
the function continue to add padding as needed though.
* cipher/mac-poly1305.c: If the caller requested to finish the hash
function without a copy of the result, return immediately.
--
Caught by UndefinedBehaviorSanitizer.
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
-rw-r--r-- | cipher/cipher-gcm.c | 2 | ||||
-rw-r--r-- | cipher/mac-poly1305.c | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/cipher/cipher-gcm.c b/cipher/cipher-gcm.c index 6b13fc55..3711a1df 100644 --- a/cipher/cipher-gcm.c +++ b/cipher/cipher-gcm.c @@ -474,7 +474,7 @@ do_ghash_buf(gcry_cipher_hd_t c, byte *hash, const byte *buf, do { - if (buflen + unused < blocksize || unused > 0) + if (buflen > 0 && (buflen + unused < blocksize || unused > 0)) { n = blocksize - unused; n = n < buflen ? n : buflen; diff --git a/cipher/mac-poly1305.c b/cipher/mac-poly1305.c index 76b369ac..b80f87db 100644 --- a/cipher/mac-poly1305.c +++ b/cipher/mac-poly1305.c @@ -260,6 +260,9 @@ poly1305mac_read (gcry_mac_hd_t h, unsigned char *outbuf, size_t *outlen) mac_ctx->marks.tag = 1; } + if (*outlen == 0) + return 0; + if (*outlen <= POLY1305_TAGLEN) buf_cpy (outbuf, mac_ctx->tag, *outlen); else |