1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-05-31 22:18:03 +02:00

* 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.
This commit is contained in:
David Shaw 2007-04-06 03:46:03 +00:00
parent 61bcf36235
commit 82a8277b6c
2 changed files with 67 additions and 22 deletions

View File

@ -1,3 +1,12 @@
2007-04-05 David Shaw <dshaw@jabberwocky.com>
From STABLE-BRANCH-1-4
* 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.
2007-03-14 David Shaw <dshaw@jabberwocky.com> 2007-03-14 David Shaw <dshaw@jabberwocky.com>
From STABLE-BRANCH-1-4 From STABLE-BRANCH-1-4

View File

@ -1,6 +1,6 @@
/* parse-packet.c - read packets /* parse-packet.c - read packets
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
* 2006 Free Software Foundation, Inc. * 2007 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * 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, static void skip_packet( IOBUF inp, int pkttype,
unsigned long pktlen, int partial ); unsigned long pktlen, int partial );
static void *read_rest( IOBUF inp, size_t 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, static int parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
PACKET *packet ); PACKET *packet );
static int parse_pubkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, 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: case PKT_GPG_CONTROL:
rc = parse_gpg_control(inp, pkttype, pktlen, pkt, partial ); rc = parse_gpg_control(inp, pkttype, pktlen, pkt, partial );
break; break;
case PKT_MARKER:
rc = parse_marker(inp,pkttype,pktlen);
break;
default: default:
skip_packet(inp, pkttype, pktlen, partial); skip_packet(inp, pkttype, pktlen, partial);
break; break;
@ -644,32 +648,31 @@ copy_packet( IOBUF inp, IOBUF out, int pkttype,
static void static void
skip_packet( IOBUF inp, int pkttype, unsigned long pktlen, int partial ) skip_packet( IOBUF inp, int pkttype, unsigned long pktlen, int partial )
{ {
if( list_mode ) { if( list_mode )
if( pkttype == PKT_MARKER ) {
fputs(":marker packet:\n", listfp ); fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
else pkttype, pktlen);
fprintf (listfp, ":unknown packet: type %2d, length %lu\n", if( pkttype )
pkttype, pktlen); {
if( pkttype ) { int c, i=0 ;
int c, i=0 ; fputs("dump:", listfp );
if( pkttype != PKT_MARKER ) if( partial )
fputs("dump:", listfp ); {
if( partial ) { while( (c=iobuf_get(inp)) != -1 )
while( (c=iobuf_get(inp)) != -1 ) dump_hex_line(c, &i);
dump_hex_line(c, &i);
} }
else { else
for( ; pktlen; pktlen-- ) {
dump_hex_line(iobuf_get(inp), &i); for( ; pktlen; pktlen-- )
dump_hex_line(iobuf_get(inp), &i);
} }
putc ('\n', listfp); putc ('\n', listfp);
return; return;
} }
} }
iobuf_skip_rest(inp,pktlen,partial); iobuf_skip_rest(inp,pktlen,partial);
} }
static void * static void *
read_rest( IOBUF inp, size_t pktlen, int partial ) read_rest( IOBUF inp, size_t pktlen, int partial )
{ {
@ -688,7 +691,40 @@ read_rest( IOBUF inp, size_t pktlen, int partial )
return p; 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 static int
parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet ) parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )