diff options
author | Werner Koch <[email protected]> | 2022-08-31 11:35:41 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2022-08-31 11:35:41 +0000 |
commit | aa0c942521d89f4f0aac90bacaf8a7a7cefc88d8 (patch) | |
tree | f4c79942479ebc89dd88d6bdb0bedd82e073ae7d | |
parent | gpg: Make --require-compliance work for -se (diff) | |
download | gnupg-aa0c942521d89f4f0aac90bacaf8a7a7cefc88d8.tar.gz gnupg-aa0c942521d89f4f0aac90bacaf8a7a7cefc88d8.zip |
gpg: Fix assertion failure due to errors in encrypt_filter.
* common/iobuf.c (iobuf_copy): Use log_assert. Explicitly cast error
return value.
* g10/build-packet.c (do_plaintext): Check for iobuf_copy error.
* g10/encrypt.c (encrypt_filter): Immediately set header_okay.
--
Fixes-commit: 8066f8a3470f9d2f3682a28641a7b09eca29a105
which caused the assertion failure on error.
The second fix avoids repeated error message about non-compliant keys.
GnuPG-bug-id: 6174
-rw-r--r-- | common/iobuf.c | 8 | ||||
-rw-r--r-- | g10/build-packet.c | 3 | ||||
-rw-r--r-- | g10/encrypt.c | 4 |
3 files changed, 9 insertions, 6 deletions
diff --git a/common/iobuf.c b/common/iobuf.c index 07edbbefd..6370efbfe 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -2201,7 +2201,7 @@ iobuf_temp_to_buffer (iobuf_t a, byte * buffer, size_t buflen) /* Copies the data from the input iobuf SOURCE to the output iobuf DEST until either an error is encountered or EOF is reached. - Returns the number of bytes copies. */ + Returns the number of bytes copies or (size_t)(-1) on error. */ size_t iobuf_copy (iobuf_t dest, iobuf_t source) { @@ -2214,11 +2214,11 @@ iobuf_copy (iobuf_t dest, iobuf_t source) size_t max_read = 0; int err; - assert (source->use == IOBUF_INPUT || source->use == IOBUF_INPUT_TEMP); - assert (dest->use == IOBUF_OUTPUT || source->use == IOBUF_OUTPUT_TEMP); + log_assert (source->use == IOBUF_INPUT || source->use == IOBUF_INPUT_TEMP); + log_assert (dest->use == IOBUF_OUTPUT || source->use == IOBUF_OUTPUT_TEMP); if (iobuf_error (dest)) - return -1; + return (size_t)(-1); temp = xmalloc (temp_size); while (1) diff --git a/g10/build-packet.c b/g10/build-packet.c index 266bf54e4..a40ed0d82 100644 --- a/g10/build-packet.c +++ b/g10/build-packet.c @@ -753,6 +753,9 @@ do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt ) if (pt->buf) { nbytes = iobuf_copy (out, pt->buf); + if (nbytes == (size_t)(-1) + && (iobuf_error (out) || iobuf_error (pt->buf))) + return iobuf_error (out)? iobuf_error (out):iobuf_error (pt->buf); if(ctb_new_format_p (ctb) && !pt->len) /* Turn off partial body length mode. */ iobuf_set_partial_body_length_mode (out, 0); diff --git a/g10/encrypt.c b/g10/encrypt.c index 4b055fd26..aba161ddd 100644 --- a/g10/encrypt.c +++ b/g10/encrypt.c @@ -878,6 +878,8 @@ encrypt_filter (void *opaque, int control, { if ( !efx->header_okay ) { + efx->header_okay = 1; + efx->cfx.dek = create_dek_with_warnings (0, efx->pk_list); rc = check_encryption_compliance (efx->cfx.dek, efx->pk_list); @@ -904,8 +906,6 @@ encrypt_filter (void *opaque, int control, } iobuf_push_filter (a, cipher_filter_cfb, &efx->cfx); - - efx->header_okay = 1; } rc = iobuf_write (a, buf, size); |