[LIBGPG-ERROR PATCH] estream read/write access

NIIBE Yutaka gniibe at fsij.org
Tue Jun 14 03:18:58 CEST 2016


I'm looking at the issue 2371:

I think that this bug (in libgpg-error for gpg 2.1) should be fixed

This bug is revealed by the change of GPG:


    commit 12af2630cf4d1a39179179925fac8f2cce7504ff
    Author: Justus Winter <justus at g10code.com>
    Date:   Fri Apr 8 19:21:12 2016 +0200

        common: Add support for the new extended private key format.

        * agent/findkey.c (write_extended_private_key): New function.
        (agent_write_private_key): Detect if an existing file is in extended
        format and update the key within if it is.
        (read_key_file): Handle the new format.

No, this change itself is valid and nothing wrong.

However, this is the first instance for estream to do READ and WRITE
(in the history of the code > 10 years :-).  In the function
agent_write_private_key, the pattern is:


which should work well, but if results core dump by assertion failure
in the function es_flush of libgpg-error.

Here is a fix.

diff --git a/src/estream.c b/src/estream.c
index 499cc75..14576d3 100644
--- a/src/estream.c
+++ b/src/estream.c
@@ -2671,6 +2671,7 @@ es_writen (estream_t _GPGRT__RESTRICT stream,
                 goto out;
+          stream->flags.writing = 1;

@@ -2693,9 +2694,6 @@ es_writen (estream_t _GPGRT__RESTRICT stream,

   if (bytes_written)
     *bytes_written = data_written;
-  if (data_written)
-    if (!stream->flags.writing)
-      stream->flags.writing = 1;

   return err;

More information about the Gnupg-devel mailing list