diff --git a/common/iobuf.c b/common/iobuf.c index 1f2cd3f5d..a0d48c669 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -2253,6 +2253,9 @@ iobuf_copy (iobuf_t dest, iobuf_t source) break; nwrote += nread; } + + /* Burn the buffer. */ + wipememory (temp, sizeof (temp)); xfree (temp); return nwrote; diff --git a/g10/build-packet.c b/g10/build-packet.c index 4dec5b94f..a6d588115 100644 --- a/g10/build-packet.c +++ b/g10/build-packet.c @@ -528,33 +528,23 @@ calc_plaintext( PKT_plaintext *pt ) static int do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt ) { - int i, rc = 0; - u32 n; - byte buf[1000]; /* this buffer has the plaintext! */ - int nbytes; + int rc = 0; + size_t nbytes; write_header(out, ctb, calc_plaintext( pt ) ); iobuf_put(out, pt->mode ); iobuf_put(out, pt->namelen ); - for(i=0; i < pt->namelen; i++ ) - iobuf_put(out, pt->name[i] ); + iobuf_write (out, pt->name, pt->namelen); rc = write_32(out, pt->timestamp ); if (rc) return rc; - n = 0; - while( (nbytes=iobuf_read(pt->buf, buf, 1000)) != -1 ) { - rc = iobuf_write (out, buf, nbytes); - if (rc) - break; - n += nbytes; - } - wipememory(buf,1000); /* burn the buffer */ + nbytes = iobuf_copy (out, pt->buf); if( (ctb&0x40) && !pt->len ) iobuf_set_partial_body_length_mode(out, 0 ); /* turn off partial */ - if( pt->len && n != pt->len ) + if( pt->len && nbytes != pt->len ) log_error("do_plaintext(): wrote %lu bytes but expected %lu bytes\n", - (ulong)n, (ulong)pt->len ); + (ulong)nbytes, (ulong)pt->len ); return rc; }