aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/iobuf.c7
-rw-r--r--g10/plaintext.c19
-rw-r--r--g10/sign.c6
3 files changed, 19 insertions, 13 deletions
diff --git a/common/iobuf.c b/common/iobuf.c
index ace745542..822eabe1a 100644
--- a/common/iobuf.c
+++ b/common/iobuf.c
@@ -2298,9 +2298,7 @@ size_t
iobuf_copy (iobuf_t dest, iobuf_t source)
{
char *temp;
- /* Use a 32 KB buffer. */
- const size_t temp_size = 32 * 1024;
-
+ size_t temp_size;
size_t nread;
size_t nwrote = 0;
size_t max_read = 0;
@@ -2312,6 +2310,9 @@ iobuf_copy (iobuf_t dest, iobuf_t source)
if (iobuf_error (dest))
return -1;
+ /* Use iobuf buffer size for temporary buffer. */
+ temp_size = iobuf_set_buffer_size(0) * 1024;
+
temp = xmalloc (temp_size);
while (1)
{
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);
diff --git a/g10/sign.c b/g10/sign.c
index 981cc250a..bbcfabdb7 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -1294,6 +1294,8 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
/* Setup the inner packet. */
if (detached)
{
+ size_t iobuf_size = iobuf_set_buffer_size(0) * 1024;
+
if (multifile)
{
strlist_t sl;
@@ -1328,7 +1330,7 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
iobuf_push_filter (inp, text_filter, &tfx);
}
iobuf_push_filter (inp, md_filter, &mfx);
- while (iobuf_read (inp, NULL, 1<<30) != -1)
+ while (iobuf_read (inp, NULL, iobuf_size) != -1)
;
iobuf_close (inp);
inp = NULL;
@@ -1339,7 +1341,7 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
else
{
/* Read, so that the filter can calculate the digest. */
- while (iobuf_read (inp, NULL, 1<<30) != -1)
+ while (iobuf_read (inp, NULL, iobuf_size) != -1)
;
}
}