diff --git a/g10/ChangeLog b/g10/ChangeLog index cffdbf3f2..d529054e5 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,10 @@ +2004-03-26 David Shaw + + * build-packet.c (calc_plaintext, do_plaintext): Do not create + illegal (packet header indicates a size larger than the actual + packet) encrypted data packets when not compressing and using a + filename longer than 255 characters. + 2004-03-25 David Shaw * options.h, g10.c (main), compress-bz2.c (init_uncompress): diff --git a/g10/build-packet.c b/g10/build-packet.c index f583828a8..b3bb3f32a 100644 --- a/g10/build-packet.c +++ b/g10/build-packet.c @@ -528,7 +528,14 @@ do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc ) static u32 calc_plaintext( PKT_plaintext *pt ) { - return pt->len? (1 + 1 + pt->namelen + 4 + pt->len) : 0; + /* Truncate namelen to the maximum 255 characters. Note this means + that a function that calls build_packet with an illegal literal + packet will get it back legalized. */ + + if(pt->namelen>255) + pt->namelen=255; + + return pt->len? (1 + 1 + pt->namelen + 4 + pt->len) : 0; } static int @@ -539,12 +546,6 @@ do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt ) byte buf[1000]; /* this buffer has the plaintext! */ int nbytes; - /* Truncate namelen to the maximum 255 characters. This does mean - that a function that calls build_packet with an illegal literal - packet will get it back legalized. */ - if(pt->namelen>255) - pt->namelen=255; - write_header(out, ctb, calc_plaintext( pt ) ); iobuf_put(out, pt->mode ); iobuf_put(out, pt->namelen );