diff options
author | Justus Winter <[email protected]> | 2016-10-18 15:57:19 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2016-10-18 16:54:49 +0000 |
commit | 8dce5ee55a0268d196023224dcf3020306922490 (patch) | |
tree | 4f5d4e10091e6d8618e233b2aff3a4bf11009c06 /common/exectool.c | |
parent | common,w32: Communicate with child in non-blocking mode. (diff) | |
download | gnupg-8dce5ee55a0268d196023224dcf3020306922490.tar.gz gnupg-8dce5ee55a0268d196023224dcf3020306922490.zip |
common: Fix copying data to estreams.
* common/exectool.c (copy_buffer_do_copy): Correctly account for
partially written data in the event of errors.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'common/exectool.c')
-rw-r--r-- | common/exectool.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/common/exectool.c b/common/exectool.c index e46071c44..cf54efe6e 100644 --- a/common/exectool.c +++ b/common/exectool.c @@ -248,7 +248,14 @@ copy_buffer_do_copy (struct copy_buffer *c, estream_t source, estream_t sink) return 0; /* Done copying. */ + nwritten = 0; err = sink? es_write (sink, c->writep, c->nread, &nwritten) : 0; + + assert (nwritten <= c->nread); + c->writep += nwritten; + c->nread -= nwritten; + assert (c->writep - c->buffer <= sizeof c->buffer); + if (err) { if (errno == EAGAIN) @@ -257,11 +264,6 @@ copy_buffer_do_copy (struct copy_buffer *c, estream_t source, estream_t sink) return my_error_from_syserror (); } - assert (nwritten <= c->nread); - c->writep += nwritten; - c->nread -= nwritten; - assert (c->writep - c->buffer <= sizeof c->buffer); - if (sink && es_fflush (sink) && errno != EAGAIN) err = my_error_from_syserror (); |