1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

gpg: Print status line and proper diagnostics for write errors.

* common/iobuf.c (file_filter): Improve diagnostics.
* g10/build-packet.c (do_plaintext): Make sure to cache all error
cases.
--

GnuPG-bug-id: 6528
This commit is contained in:
Werner Koch 2023-06-09 17:40:53 +02:00
parent 64509134d4
commit 695cb04af5
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 17 additions and 6 deletions

View File

@ -503,7 +503,8 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf,
if (ec != ERROR_BROKEN_PIPE) if (ec != ERROR_BROKEN_PIPE)
{ {
rc = gpg_error_from_errno (ec); rc = gpg_error_from_errno (ec);
log_error ("%s: read error: ec=%d\n", a->fname, ec); log_error ("%s: read error: %s (ec=%d)\n",
a->fname, gpg_strerror (rc), ec);
} }
} }
else if (!nread) else if (!nread)
@ -573,7 +574,8 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf,
{ {
int ec = (int) GetLastError (); int ec = (int) GetLastError ();
rc = gpg_error_from_errno (ec); rc = gpg_error_from_errno (ec);
log_error ("%s: write error: ec=%d\n", a->fname, ec); log_error ("%s: write error: %s (ec=%d)\n",
a->fname, gpg_strerror (rc), ec);
break; break;
} }
p += n; p += n;
@ -632,7 +634,8 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf,
if (ec != ERROR_BROKEN_PIPE) if (ec != ERROR_BROKEN_PIPE)
{ {
rc = gpg_error_from_errno (ec); rc = gpg_error_from_errno (ec);
log_error ("%s: read error: ec=%d\n", a->fname, ec); log_error ("%s: read error: %s (ec=%d)\n",
a->fname, gpg_strerror (rc), ec);
} }
a->npeeked = 0; a->npeeked = 0;
} }

View File

@ -991,12 +991,20 @@ do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt )
if (nbytes == (size_t)(-1) if (nbytes == (size_t)(-1)
&& (iobuf_error (out) || iobuf_error (pt->buf))) && (iobuf_error (out) || iobuf_error (pt->buf)))
return iobuf_error (out)? iobuf_error (out):iobuf_error (pt->buf); return iobuf_error (out)? iobuf_error (out):iobuf_error (pt->buf);
/* Always get the error to catch write errors because
* iobuf_copy does not reliable return (-1) in that case. */
rc = iobuf_error (out);
if(ctb_new_format_p (ctb) && !pt->len) if(ctb_new_format_p (ctb) && !pt->len)
/* Turn off partial body length mode. */ /* Turn off partial body length mode. */
iobuf_set_partial_body_length_mode (out, 0); iobuf_set_partial_body_length_mode (out, 0);
if( pt->len && nbytes != pt->len ) if (pt->len && nbytes != pt->len)
log_error("do_plaintext(): wrote %lu bytes but expected %lu bytes\n", {
log_error ("do_plaintext(): wrote %lu bytes"
" but expected %lu bytes\n",
(ulong)nbytes, (ulong)pt->len ); (ulong)nbytes, (ulong)pt->len );
if (!rc) /* Just in case no error was set */
rc = gpg_error (GPG_ERR_EIO);
}
} }
return rc; return rc;