* parse-packet.c (parse): Only data-type packets are allowed to use
authorDavid Shaw <dshaw@jabberwocky.com>
Mon, 1 Mar 2004 23:10:35 +0000 (23:10 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Mon, 1 Mar 2004 23:10:35 +0000 (23:10 +0000)
OpenPGP partial length encoding.

g10/ChangeLog
g10/parse-packet.c

index 3f0d630..57903f2 100644 (file)
@@ -1,3 +1,8 @@
+2004-03-01  David Shaw  <dshaw@jabberwocky.com>
+
+       * parse-packet.c (parse): Only data-type packets are allowed to
+       use OpenPGP partial length encoding.
+
 2004-02-25  David Shaw  <dshaw@jabberwocky.com>
 
        * delkey.c (do_delete_key): Allow deleting a public key with a
index a99ebdb..559a068 100644 (file)
@@ -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 {