From 9eb128ef9bc4424e5d604e7b38fbefcb24202afb Mon Sep 17 00:00:00 2001 From: David Shaw Date: Mon, 1 Mar 2004 23:10:35 +0000 Subject: [PATCH] * parse-packet.c (parse): Only data-type packets are allowed to use OpenPGP partial length encoding. --- g10/ChangeLog | 5 ++++ g10/parse-packet.c | 74 ++++++++++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 3f0d6308e..57903f2df 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,8 @@ +2004-03-01 David Shaw + + * parse-packet.c (parse): Only data-type packets are allowed to + use OpenPGP partial length encoding. + 2004-02-25 David Shaw * delkey.c (do_delete_key): Allow deleting a public key with a diff --git a/g10/parse-packet.c b/g10/parse-packet.c index a99ebdba3..559a068c5 100644 --- a/g10/parse-packet.c +++ b/g10/parse-packet.c @@ -332,34 +332,52 @@ parse( IOBUF inp, PACKET *pkt, int onlykeypkts, off_t *retpos, else { hdr[hdrlen++] = c; if( c < 192 ) - pktlen = c; - else if( c < 224 ) { - pktlen = (c - 192) * 256; - if( (c = iobuf_get(inp)) == -1 ) { - log_error("%s: 2nd length byte missing\n", - iobuf_where(inp) ); - rc = G10ERR_INVALID_PACKET; - goto leave; - } - hdr[hdrlen++] = c; - pktlen += c + 192; - } - else if( c == 255 ) { - pktlen = (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 24; - pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 16; - pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 8; - if( (c = iobuf_get(inp)) == -1 ) { - log_error("%s: 4 byte length invalid\n", - iobuf_where(inp) ); - rc = G10ERR_INVALID_PACKET; - goto leave; - } - pktlen |= (hdr[hdrlen++] = c ); - } - else { /* partial body length */ - iobuf_set_partial_block_mode(inp, c & 0xff); - pktlen = 0;/* to indicate partial length */ - } + pktlen = c; + else if( c < 224 ) + { + pktlen = (c - 192) * 256; + if( (c = iobuf_get(inp)) == -1 ) + { + log_error("%s: 2nd length byte missing\n", + iobuf_where(inp) ); + rc = G10ERR_INVALID_PACKET; + goto leave; + } + hdr[hdrlen++] = c; + pktlen += c + 192; + } + else if( c == 255 ) + { + pktlen = (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 24; + pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 16; + pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 8; + if( (c = iobuf_get(inp)) == -1 ) + { + log_error("%s: 4 byte length invalid\n", + iobuf_where(inp) ); + rc = G10ERR_INVALID_PACKET; + goto leave; + } + pktlen |= (hdr[hdrlen++] = c ); + } + else + { + /* Partial body length. Note that we handled + PKT_COMPRESSED earlier. */ + if(pkttype==PKT_PLAINTEXT || pkttype==PKT_ENCRYPTED + || pkttype==PKT_ENCRYPTED_MDC) + { + iobuf_set_partial_block_mode(inp, c & 0xff); + pktlen = 0;/* to indicate partial length */ + } + else + { + log_error("%s: partial length for invalid" + " packet type %d\n",iobuf_where(inp),pkttype); + rc=G10ERR_INVALID_PACKET; + goto leave; + } + } } } else {