aboutsummaryrefslogtreecommitdiffstats
path: root/g10/parse-packet.c
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2007-04-06 03:46:03 +0000
committerDavid Shaw <[email protected]>2007-04-06 03:46:03 +0000
commit82a8277b6cc6a5ab5f1b024396c43bca3f3f6ebc (patch)
tree9317d7d1c56d098cdf8cae125acb5822d26fc154 /g10/parse-packet.c
parent * trustlist.c (read_trustfiles): Take a missing trustlist as an (diff)
downloadgnupg-82a8277b6cc6a5ab5f1b024396c43bca3f3f6ebc.tar.gz
gnupg-82a8277b6cc6a5ab5f1b024396c43bca3f3f6ebc.zip
* parse-packet.c (parse_marker): New. Enforce that the marker
contains 'P', 'G', 'P', and nothing but. (parse): Call it here. (skip_packet): No longer need to handle marker packets here.
Diffstat (limited to 'g10/parse-packet.c')
-rw-r--r--g10/parse-packet.c80
1 files changed, 58 insertions, 22 deletions
diff --git a/g10/parse-packet.c b/g10/parse-packet.c
index 5d5d14a56..90201d6be 100644
--- a/g10/parse-packet.c
+++ b/g10/parse-packet.c
@@ -1,6 +1,6 @@
/* parse-packet.c - read packets
- * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
- * 2006 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ * 2007 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -52,6 +52,7 @@ static int copy_packet( IOBUF inp, IOBUF out, int pkttype,
static void skip_packet( IOBUF inp, int pkttype,
unsigned long pktlen, int partial );
static void *read_rest( IOBUF inp, size_t pktlen, int partial );
+static int parse_marker( IOBUF inp, int pkttype, unsigned long pktlen );
static int parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
PACKET *packet );
static int parse_pubkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
@@ -579,6 +580,9 @@ parse( IOBUF inp, PACKET *pkt, int onlykeypkts, off_t *retpos,
case PKT_GPG_CONTROL:
rc = parse_gpg_control(inp, pkttype, pktlen, pkt, partial );
break;
+ case PKT_MARKER:
+ rc = parse_marker(inp,pkttype,pktlen);
+ break;
default:
skip_packet(inp, pkttype, pktlen, partial);
break;
@@ -644,32 +648,31 @@ copy_packet( IOBUF inp, IOBUF out, int pkttype,
static void
skip_packet( IOBUF inp, int pkttype, unsigned long pktlen, int partial )
{
- if( list_mode ) {
- if( pkttype == PKT_MARKER )
- fputs(":marker packet:\n", listfp );
- else
- fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
- pkttype, pktlen);
- if( pkttype ) {
- int c, i=0 ;
- if( pkttype != PKT_MARKER )
- fputs("dump:", listfp );
- if( partial ) {
- while( (c=iobuf_get(inp)) != -1 )
- dump_hex_line(c, &i);
+ if( list_mode )
+ {
+ fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
+ pkttype, pktlen);
+ if( pkttype )
+ {
+ int c, i=0 ;
+ fputs("dump:", listfp );
+ if( partial )
+ {
+ while( (c=iobuf_get(inp)) != -1 )
+ dump_hex_line(c, &i);
}
- else {
- for( ; pktlen; pktlen-- )
- dump_hex_line(iobuf_get(inp), &i);
+ else
+ {
+ for( ; pktlen; pktlen-- )
+ dump_hex_line(iobuf_get(inp), &i);
}
- putc ('\n', listfp);
- return;
+ putc ('\n', listfp);
+ return;
}
}
- iobuf_skip_rest(inp,pktlen,partial);
+ iobuf_skip_rest(inp,pktlen,partial);
}
-
static void *
read_rest( IOBUF inp, size_t pktlen, int partial )
{
@@ -688,7 +691,40 @@ read_rest( IOBUF inp, size_t pktlen, int partial )
return p;
}
+static int
+parse_marker( IOBUF inp, int pkttype, unsigned long pktlen )
+{
+ if(pktlen!=3)
+ goto fail;
+
+ if(iobuf_get(inp)!='P')
+ {
+ pktlen--;
+ goto fail;
+ }
+
+ if(iobuf_get(inp)!='G')
+ {
+ pktlen--;
+ goto fail;
+ }
+ if(iobuf_get(inp)!='P')
+ {
+ pktlen--;
+ goto fail;
+ }
+
+ if(list_mode)
+ fputs(":marker packet: PGP\n", listfp );
+
+ return 0;
+
+ fail:
+ log_error("invalid marker packet\n");
+ iobuf_skip_rest(inp,pktlen,0);
+ return G10ERR_INVALID_PACKET;
+}
static int
parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )