diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2017-05-31 11:42:55 +0200 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2017-05-31 11:42:55 +0200 |
commit | c03e0eb01dc4632432d0472a6f8051142082bea4 (patch) | |
tree | 94f2f54690f2bcf4908d81ecc00e3872d5fff4b1 /agent/protect.c | |
parent | scd: Fix error code on failure at usb_init. (diff) | |
download | gnupg2-c03e0eb01dc4632432d0472a6f8051142082bea4.tar.xz gnupg2-c03e0eb01dc4632432d0472a6f8051142082bea4.zip |
agent: Fix error from do_encryption.
* agent/protect.c (do_encryption): Don't mask failure of OUTBUF
allocation.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to '')
-rw-r--r-- | agent/protect.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/agent/protect.c b/agent/protect.c index 66c37410d..18b44f136 100644 --- a/agent/protect.c +++ b/agent/protect.c @@ -381,7 +381,10 @@ do_encryption (const unsigned char *hashbegin, size_t hashlen, outbuf = gcry_malloc_secure (outlen); } if (!outbuf) - rc = out_of_core (); + { + rc = out_of_core (); + goto leave; + } /* Allocate a buffer for the nonce and the salt. */ if (!rc) @@ -421,11 +424,13 @@ do_encryption (const unsigned char *hashbegin, size_t hashlen, } } + if (rc) + goto leave; + /* Set the IV/nonce. */ - if (!rc) - { - rc = gcry_cipher_setiv (hd, iv, use_ocb? 12 : blklen); - } + rc = gcry_cipher_setiv (hd, iv, use_ocb? 12 : blklen); + if (rc) + goto leave; if (use_ocb) { @@ -436,7 +441,6 @@ do_encryption (const unsigned char *hashbegin, size_t hashlen, if (!rc) rc = gcry_cipher_authenticate (hd, protbegin+protlen, hashlen - (protbegin+protlen - hashbegin)); - } else { @@ -500,14 +504,11 @@ do_encryption (const unsigned char *hashbegin, size_t hashlen, } } + if (rc) + goto leave; + /* Release cipher handle and check for errors. */ gcry_cipher_close (hd); - if (rc) - { - xfree (iv); - xfree (outbuf); - return rc; - } /* Now allocate the buffer we want to return. This is @@ -546,6 +547,12 @@ do_encryption (const unsigned char *hashbegin, size_t hashlen, xfree (iv); xfree (outbuf); return 0; + + leave: + gcry_cipher_close (hd); + xfree (iv); + xfree (outbuf); + return rc; } |