common: Make gnupg_exec_tool conform to spec.

* common/exectool.c (gnupg_exec_tool): Allocate extra byte.  Allow
zero length read.  Append hidden byte.  Release memory on error.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-02-02 18:18:31 +01:00
parent 81494fd30d
commit d19d6e1856
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 18 additions and 9 deletions

View File

@ -417,24 +417,33 @@ gnupg_exec_tool (const char *pgmname, const char *argv[],
if (err)
goto leave;
*result = xtrymalloc (len);
if (*result == NULL)
*result = xtrymalloc (len + 1);
if (!*result)
{
err = my_error_from_syserror ();
goto leave;
}
err = es_read (output, *result, len, &nread);
if (! err)
if (len)
{
assert (nread == len || !"short read on memstream");
if (resultlen)
*resultlen = len;
err = es_read (output, *result, len, &nread);
if (err)
goto leave;
if (nread != len)
log_fatal ("%s: short read from memstream\n", __func__);
}
(*result)[len] = 0;
if (resultlen)
*resultlen = len;
leave:
if (input)
es_fclose (input);
es_fclose (input);
es_fclose (output);
if (err)
{
xfree (*result);
*result = NULL;
}
return err;
}