[Pkg-gnupg-commit] [gnupg2] 63/205: gpg: Use higher-level functions.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed May 11 08:38:17 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch experimental
in repository gnupg2.
commit 33ac735a781325c4d47cdf6216813866ab93562e
Author: Neal H. Walfield <neal at g10code.com>
Date: Tue Feb 23 21:07:09 2016 +0100
gpg: Use higher-level functions.
* g10/build-packet.c (do_symkey_enc): Use iobuf_write instead of
iobuf_put in a loop. Use iobuf_copy instead of iobuf_read and
iobuf_write in a loop. Move the memory wiping from here...
* common/iobuf.c (iobuf_copy): ... to here.
--
Signed-off-by: Neal H. Walfield <neal at g10code.com>
---
common/iobuf.c | 3 +++
g10/build-packet.c | 22 ++++++----------------
2 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/common/iobuf.c b/common/iobuf.c
index 1f2cd3f..a0d48c6 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 4dec5b9..a6d5881 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;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list