summaryrefslogtreecommitdiffstats
path: root/g10/plaintext.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2022-02-12 19:37:48 +0100
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2022-03-08 19:00:31 +0100
commitf2322ff942fabd55de0a1272b1fcca534e623bd1 (patch)
tree06d299bec082d33231ef80688e83de4a0649c20f /g10/plaintext.c
parentgpgtar,w32: Support file names longer than MAX_PATH. (diff)
downloadgnupg2-f2322ff942fabd55de0a1272b1fcca534e623bd1.tar.xz
gnupg2-f2322ff942fabd55de0a1272b1fcca534e623bd1.zip
Use iobuf buffer size for temporary buffer size
* common/iobuf.c (iobuf_copy): Use iobuf buffer size for temporary buffers. * g10/plaintext.c (handle_plaintext, do_hash): Likewise. * g10/sign.c (sign_file): Likewise. -- As iobuf will have zerocopy operation for read/write, it is better to use same size buffers as iobuf for temporary copy buffers. GnuPG-bug-id: T5828 Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'g10/plaintext.c')
-rw-r--r--g10/plaintext.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/g10/plaintext.c b/g10/plaintext.c
index f20057cbb..a1bbbd95f 100644
--- a/g10/plaintext.c
+++ b/g10/plaintext.c
@@ -291,10 +291,11 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
}
else /* Binary mode. */
{
- byte *buffer = xmalloc (32768);
+ size_t temp_size = iobuf_set_buffer_size(0) * 1024;
+ byte *buffer = xmalloc (temp_size);
while (pt->len)
{
- int len = pt->len > 32768 ? 32768 : pt->len;
+ int len = pt->len > temp_size ? temp_size : pt->len;
len = iobuf_read (pt->buf, buffer, len);
if (len == -1)
{
@@ -366,10 +367,11 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
}
else
{ /* binary mode */
+ size_t temp_size = iobuf_set_buffer_size(0) * 1024;
byte *buffer;
int eof_seen = 0;
- buffer = xtrymalloc (32768);
+ buffer = xtrymalloc (temp_size);
if (!buffer)
{
err = gpg_error_from_syserror ();
@@ -378,16 +380,16 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
while (!eof_seen)
{
- /* Why do we check for len < 32768:
+ /* Why do we check for len < temp_size:
* If we won't, we would practically read 2 EOFs but
* the first one has already popped the block_filter
* off and therefore we don't catch the boundary.
* So, always assume EOF if iobuf_read returns less bytes
* then requested */
- int len = iobuf_read (pt->buf, buffer, 32768);
+ int len = iobuf_read (pt->buf, buffer, temp_size);
if (len == -1)
break;
- if (len < 32768)
+ if (len < temp_size)
eof_seen = 1;
if (mfx->md)
gcry_md_write (mfx->md, buffer, len);
@@ -545,10 +547,11 @@ do_hash (gcry_md_hd_t md, gcry_md_hd_t md2, IOBUF fp, int textmode)
}
else
{
- byte *buffer = xmalloc (32768);
+ size_t temp_size = iobuf_set_buffer_size(0) * 1024;
+ byte *buffer = xmalloc (temp_size);
int ret;
- while ((ret = iobuf_read (fp, buffer, 32768)) != -1)
+ while ((ret = iobuf_read (fp, buffer, temp_size)) != -1)
{
if (md)
gcry_md_write (md, buffer, ret);