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 <justus@g10code.com>
This commit is contained in:
Justus Winter 2016-10-18 17:57:19 +02:00
parent 05a1e41233
commit 8dce5ee55a
1 changed files with 7 additions and 5 deletions

View File

@ -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 ();