From 46f9b0071f54191cbf05ae23b24961ac6f43de4e Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 31 Aug 2022 13:35:41 +0200 Subject: 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. -- The second fix avoids repeated error message about non-compliant keys. Updates-commit: a51067a21f688086bd8e44234a88ae367582cc76 Ported-from: aa0c942521d89f4f0aac90bacaf8a7a7cefc88d8 GnuPG-bug-id: 6174 --- g10/build-packet.c | 3 +++ g10/encrypt.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'g10') diff --git a/g10/build-packet.c b/g10/build-packet.c index a631db8d8..cc953557d 100644 --- a/g10/build-packet.c +++ b/g10/build-packet.c @@ -970,6 +970,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 bd98d06e4..7218de216 100644 --- a/g10/encrypt.c +++ b/g10/encrypt.c @@ -1060,6 +1060,8 @@ encrypt_filter (void *opaque, int control, { if ( !efx->header_okay ) { + efx->header_okay = 1; + efx->cfx.dek = create_dek_with_warnings (efx->pk_list); rc = check_encryption_compliance (efx->cfx.dek, efx->pk_list); @@ -1092,7 +1094,6 @@ encrypt_filter (void *opaque, int control, /**/ : cipher_filter_cfb, &efx->cfx); - efx->header_okay = 1; } rc = iobuf_write (a, buf, size); -- cgit v1.2.3