[Pkg-gnupg-commit] [gnupg2] 88/116: common: Fix flushing copy buffers.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Tue Jan 24 04:40:57 UTC 2017


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 34fa2d79a07a079be472c3ff486debfdac8c6070
Author: Justus Winter <justus at g10code.com>
Date:   Wed Jan 18 18:14:41 2017 +0100

    common: Fix flushing copy buffers.
    
    * common/exectool.c (copy_buffer_flush): Write and flush the data, but
    do not hide EAGAIN from the caller.
    (gnupg_exec_tool_stream): Retry on EAGAIN.
    
    GnuPG-bug-id: 2425
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 common/exectool.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/common/exectool.c b/common/exectool.c
index 4593abd..0067fc6 100644
--- a/common/exectool.c
+++ b/common/exectool.c
@@ -276,15 +276,23 @@ static gpg_error_t
 copy_buffer_flush (struct copy_buffer *c, estream_t sink)
 {
   gpg_error_t err;
+  size_t nwritten;
 
-  while (c->nread > 0)
-    {
-      err = copy_buffer_do_copy (c, NULL, sink);
-      if (err)
-        return err;
-    }
+  nwritten = 0;
+  err = es_write (sink, c->writep, c->nread, &nwritten);
+
+  assert (nwritten <= c->nread);
+  c->writep += nwritten;
+  c->nread -= nwritten;
+  assert (c->writep - c->buffer <= sizeof c->buffer);
+
+  if (err)
+    return err;
 
-  return 0;
+  if (es_fflush (sink))
+    err = my_error_from_syserror ();
+
+  return err;
 }
 
 

@@ -444,6 +452,8 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
           if (es_feof (input))
             {
               err = copy_buffer_flush (cpbuf_in, fds[0].stream);
+              if (err == GPG_ERR_EAGAIN)
+                continue;	/* Retry next time.  */
               if (err)
                 {
                   log_error ("error feeding data to '%s': %s\n",
@@ -470,6 +480,8 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
           if (es_feof (inextra))
             {
               err = copy_buffer_flush (cpbuf_extra, fds[3].stream);
+              if (err == GPG_ERR_EAGAIN)
+                continue;	/* Retry next time.  */
               if (err)
                 {
                   log_error ("error feeding data to '%s': %s\n",

-- 
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