summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2016-12-26 13:15:25 -0500
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2017-01-09 07:34:40 +0100
commit16862f233f4600a4c1c827be8b1a18b6f80e0ce4 (patch)
treebfe91a68eb7efa889e83254d5645658c36dadea6
parent03d1e6089230bad79b78ce6e8ea2b872cbaf37e2 (diff)
downloadgnutls-16862f233f4600a4c1c827be8b1a18b6f80e0ce4.tar.gz
Do not infinite loop if an EOF occurs while skipping a PGP packet
Signed-off-by: Alex Gaynor <alex.gaynor@gmail.com>
-rw-r--r--lib/opencdk/read-packet.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/opencdk/read-packet.c b/lib/opencdk/read-packet.c
index becd6cb762..67ea938f72 100644
--- a/lib/opencdk/read-packet.c
+++ b/lib/opencdk/read-packet.c
@@ -42,8 +42,13 @@
static int
stream_read(cdk_stream_t s, void *buf, size_t buflen, size_t * r_nread)
{
- *r_nread = cdk_stream_read(s, buf, buflen);
- return *r_nread > 0 ? 0 : _cdk_stream_get_errno(s);
+ int res = cdk_stream_read(s, buf, buflen);
+ if (res > 0) {
+ *r_nread = res;
+ return 0;
+ } else {
+ return (cdk_stream_eof(s) ? EOF : _cdk_stream_get_errno(s));
+ }
}
@@ -875,18 +880,22 @@ read_new_length(cdk_stream_t inp,
/* Skip the current packet body. */
-static void skip_packet(cdk_stream_t inp, size_t pktlen)
+static cdk_error_t skip_packet(cdk_stream_t inp, size_t pktlen)
{
byte buf[BUFSIZE];
size_t nread, buflen = DIM(buf);
while (pktlen > 0) {
- stream_read(inp, buf, pktlen > buflen ? buflen : pktlen,
+ cdk_error_t rc;
+ rc = stream_read(inp, buf, pktlen > buflen ? buflen : pktlen,
&nread);
+ if (rc)
+ return rc;
pktlen -= nread;
}
assert(pktlen == 0);
+ return 0;
}
@@ -1087,7 +1096,9 @@ cdk_error_t cdk_pkt_read(cdk_stream_t inp, cdk_packet_t pkt)
default:
/* Skip all packets we don't understand */
- skip_packet(inp, pktlen);
+ rc = skip_packet(inp, pktlen);
+ if (rc)
+ return gnutls_assert_val(rc);
break;
}