From 95d05215c380895448fd900c1952fbadb4649bec Mon Sep 17 00:00:00 2001 From: David Shaw Date: Sun, 15 Feb 2004 00:04:32 +0000 Subject: [PATCH] * build-packet.c (write_header2): If a suggested header length is provided along with a zero length, interpret this as an actual zero length packet and not as an indeterminate length packet. (do_comment, do_user_id): Use it here as these packets might be naturally zero length. * parse-packet.c (parse): Show packet type when failing due to an indeterminate length packet. * misc.c (parse_options): Only provide args for the true (i.e. not "no-xxx") form of options. --- g10/ChangeLog | 14 +++++++++++++ g10/build-packet.c | 50 ++++++++++++++++++++++++---------------------- g10/misc.c | 16 ++++++++++----- g10/parse-packet.c | 14 ++++++------- 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index b60a6c6fe..7a1a8b871 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,17 @@ +2004-02-14 David Shaw + + * build-packet.c (write_header2): If a suggested header length is + provided along with a zero length, interpret this as an actual + zero length packet and not as an indeterminate length packet. + (do_comment, do_user_id): Use it here as these packets might be + naturally zero length. + + * parse-packet.c (parse): Show packet type when failing due to an + indeterminate length packet. + + * misc.c (parse_options): Only provide args for the true (i.e. not + "no-xxx") form of options. + 2004-02-13 David Shaw * keyserver.c (argsep): Move to misc.c. diff --git a/g10/build-packet.c b/g10/build-packet.c index 3d246afe2..fd61e4ad5 100644 --- a/g10/build-packet.c +++ b/g10/build-packet.c @@ -1,6 +1,6 @@ /* build-packet.c - assemble packets and write them - * Copyright (C) 1998, 1999, 2000, 2001, 2002, - * 2003 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, + * 2004 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -194,27 +194,32 @@ write_fake_data( IOBUF out, MPI a ) static int do_comment( IOBUF out, int ctb, PKT_comment *rem ) { - if( opt.sk_comments ) { - write_header(out, ctb, rem->len); + if( opt.sk_comments ) + { + write_header2(out, ctb, rem->len, 1, 1); if( iobuf_write( out, rem->data, rem->len ) ) - return G10ERR_WRITE_FILE; - } + return G10ERR_WRITE_FILE; + } return 0; } static int do_user_id( IOBUF out, int ctb, PKT_user_id *uid ) { - if( uid->attrib_data ) { - write_header(out, ctb, uid->attrib_len); + if( uid->attrib_data ) + { + /* Shouldn't be necessary to force a header here since attribs + can't be of zero length, but it doesn't hurt either. */ + write_header2(out, ctb, uid->attrib_len, 1, 1); if( iobuf_write( out, uid->attrib_data, uid->attrib_len ) ) - return G10ERR_WRITE_FILE; - } - else { - write_header(out, ctb, uid->len); + return G10ERR_WRITE_FILE; + } + else + { + write_header2( out, ctb, uid->len, 1, 1 ); if( iobuf_write( out, uid->name, uid->len ) ) - return G10ERR_WRITE_FILE; - } + return G10ERR_WRITE_FILE; + } return 0; } @@ -422,8 +427,6 @@ do_symkey_enc( IOBUF out, int ctb, PKT_symkey_enc *enc ) } - - static int do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc ) { @@ -456,8 +459,6 @@ do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc ) } - - static u32 calc_plaintext( PKT_plaintext *pt ) { @@ -1035,8 +1036,11 @@ write_sign_packet_header( IOBUF out, int ctb, u32 len ) } /**************** - * if HDRLEN is > 0, try to build a header of this length. - * we need this, so that we can hash packets without reading them again. + * If HDRLEN is > 0, try to build a header of this length. We need + * this so that we can hash packets without reading them again. If + * len is 0, write a partial or indeterminate length header, unless + * hdrlen is specified in which case write an actual zero length + * (using the specified hdrlen). */ static int write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode ) @@ -1045,9 +1049,7 @@ write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode ) return write_new_header( out, ctb, len, hdrlen ); if( hdrlen ) { - if( !len ) - ctb |= 3; - else if( hdrlen == 2 && len < 256 ) + if( hdrlen == 2 && len < 256 ) ; else if( hdrlen == 3 && len < 65536 ) ctb |= 1; @@ -1066,7 +1068,7 @@ write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode ) } if( iobuf_put(out, ctb ) ) return -1; - if( !len ) { + if( !len && !hdrlen ) { if( blkmode ) iobuf_set_block_mode(out, 8196 ); } diff --git a/g10/misc.c b/g10/misc.c index 01f34b4a9..500abaaa4 100644 --- a/g10/misc.c +++ b/g10/misc.c @@ -1,5 +1,5 @@ /* misc.c - miscellaneous functions - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, * 2004 Free Software Foundation, Inc. * * This file is part of GnuPG. @@ -771,11 +771,17 @@ parse_options(char *str,unsigned int *options, } if(rev) - *options&=~opts[i].bit; + { + *options&=~opts[i].bit; + if(opts[i].value) + *opts[i].value=NULL; + } else - *options|=opts[i].bit; - if(opts[i].value) - *opts[i].value=arg?m_strdup(arg):NULL; + { + *options|=opts[i].bit; + if(opts[i].value) + *opts[i].value=arg?m_strdup(arg):NULL; + } break; } } diff --git a/g10/parse-packet.c b/g10/parse-packet.c index 6bffdda52..a99ebdba3 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 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, + * 2004 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -383,11 +383,11 @@ parse( IOBUF inp, PACKET *pkt, int onlykeypkts, off_t *retpos, case PKT_COMPRESSED: break; /* the orginal pgp 2 way. */ - default: - log_error ("%s: old style partial length " - "for invalid packet type\n", iobuf_where(inp) ); - rc = G10ERR_INVALID_PACKET; - goto leave; + default: + log_error ("%s: old style partial length for invalid" + " packet type %d\n", iobuf_where(inp), pkttype ); + rc = G10ERR_INVALID_PACKET; + goto leave; } } else {