diff --git a/g10/ChangeLog b/g10/ChangeLog index 99a3d5ccd..a9786a26c 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,8 @@ +2004-06-16 David Shaw + + * keygen.c (make_backsig): Make sure that the backsig was built + successfully before we try and use it. + 2004-06-16 Werner Koch * free-packet.c (copy_secret_key): Get last fix right. diff --git a/g10/keygen.c b/g10/keygen.c index ff415c981..6b1ff98a6 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -551,69 +551,73 @@ make_backsig(PKT_signature *sig, PKT_public_key *pk, /* get it into a binary packed form. */ IOBUF backsig_out=iobuf_temp(); PACKET backsig_pkt; - byte *buf; - size_t pktlen=0; init_packet(&backsig_pkt); backsig_pkt.pkttype=PKT_SIGNATURE; backsig_pkt.pkt.signature=backsig; - build_packet(backsig_out,&backsig_pkt); + rc=build_packet(backsig_out,&backsig_pkt); free_packet(&backsig_pkt); - buf=iobuf_get_temp_buffer(backsig_out); - - /* Remove the packet header */ - if(buf[0]&0x40) - { - if(buf[1]<192) - { - pktlen=buf[1]; - buf+=2; - } - else if(buf[1]<224) - { - pktlen=(buf[1]-192)*256; - pktlen+=buf[2]+192; - buf+=3; - } - else if(buf[1]==255) - { - pktlen =buf[2] << 24; - pktlen|=buf[3] << 16; - pktlen|=buf[4] << 8; - pktlen|=buf[5]; - buf+=6; - } - else - BUG(); - } + if(rc) + log_error("build_packet failed for backsig: %s\n",g10_errstr(rc)); else - { - int mark=1; + { + size_t pktlen=0; + byte *buf=iobuf_get_temp_buffer(backsig_out); - switch(buf[0]&3) - { - case 3: - BUG(); - break; + /* Remove the packet header */ + if(buf[0]&0x40) + { + if(buf[1]<192) + { + pktlen=buf[1]; + buf+=2; + } + else if(buf[1]<224) + { + pktlen=(buf[1]-192)*256; + pktlen+=buf[2]+192; + buf+=3; + } + else if(buf[1]==255) + { + pktlen =buf[2] << 24; + pktlen|=buf[3] << 16; + pktlen|=buf[4] << 8; + pktlen|=buf[5]; + buf+=6; + } + else + BUG(); + } + else + { + int mark=1; - case 2: - pktlen =buf[mark++] << 24; - pktlen|=buf[mark++] << 16; + switch(buf[0]&3) + { + case 3: + BUG(); + break; - case 1: - pktlen|=buf[mark++] << 8; + case 2: + pktlen =buf[mark++] << 24; + pktlen|=buf[mark++] << 16; - case 0: - pktlen|=buf[mark++]; - } + case 1: + pktlen|=buf[mark++] << 8; - buf+=mark; - } + case 0: + pktlen|=buf[mark++]; + } - /* now make the binary blob into a subpacket */ - build_sig_subpkt(sig,SIGSUBPKT_SIGNATURE,buf,pktlen); + buf+=mark; + } + + /* now make the binary blob into a subpacket */ + build_sig_subpkt(sig,SIGSUBPKT_SIGNATURE,buf,pktlen); - iobuf_close(backsig_out); + iobuf_close(backsig_out); + } } return rc;