2015-12-14 09:38:46 +01:00
|
|
|
|
/* exectool.c - Utility functions to execute a helper tool
|
2015-11-30 12:53:57 +01:00
|
|
|
|
* Copyright (C) 2015 Werner Koch
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
|
*
|
2015-12-14 09:44:38 +01:00
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of either
|
2015-11-30 12:53:57 +01:00
|
|
|
|
*
|
2015-12-14 09:44:38 +01:00
|
|
|
|
* - the GNU Lesser General Public License as published by the Free
|
|
|
|
|
* Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* or
|
|
|
|
|
*
|
|
|
|
|
* - the GNU General Public License as published by the Free
|
|
|
|
|
* Software Foundation; either version 2 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* or both in parallel, as here.
|
|
|
|
|
*
|
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
2015-11-30 12:53:57 +01:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <assert.h>
|
2015-11-30 14:23:02 +01:00
|
|
|
|
#include <gpg-error.h>
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
|
|
|
|
#include <assuan.h>
|
|
|
|
|
#include "i18n.h"
|
2015-11-30 13:00:11 +01:00
|
|
|
|
#include "logging.h"
|
2015-11-30 12:53:57 +01:00
|
|
|
|
#include "membuf.h"
|
2015-11-30 14:23:02 +01:00
|
|
|
|
#include "mischelp.h"
|
2015-11-30 12:53:57 +01:00
|
|
|
|
#include "exechelp.h"
|
|
|
|
|
#include "sysutils.h"
|
2015-11-30 14:23:02 +01:00
|
|
|
|
#include "util.h"
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
const char *pgmname;
|
|
|
|
|
int cont;
|
|
|
|
|
int used;
|
|
|
|
|
char buffer[256];
|
|
|
|
|
} read_and_log_buffer_t;
|
|
|
|
|
|
|
|
|
|
|
2015-12-14 19:55:34 +01:00
|
|
|
|
static inline gpg_error_t
|
|
|
|
|
my_error_from_syserror (void)
|
|
|
|
|
{
|
|
|
|
|
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-11-30 12:53:57 +01:00
|
|
|
|
static void
|
|
|
|
|
read_and_log_stderr (read_and_log_buffer_t *state, es_poll_t *fderr)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
if (!fderr)
|
|
|
|
|
{
|
|
|
|
|
/* Flush internal buffer. */
|
|
|
|
|
if (state->used)
|
|
|
|
|
{
|
|
|
|
|
const char *pname;
|
|
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
state->buffer[state->used] = 0;
|
|
|
|
|
state->used = 0;
|
|
|
|
|
|
|
|
|
|
pname = strrchr (state->pgmname, '/');
|
|
|
|
|
if (pname && pname != state->pgmname && pname[1])
|
|
|
|
|
pname++;
|
|
|
|
|
else
|
|
|
|
|
pname = state->pgmname;
|
|
|
|
|
/* If our pgmname plus colon is identical to the start of
|
|
|
|
|
the output, print only the output. */
|
|
|
|
|
len = strlen (pname);
|
|
|
|
|
if (!state->cont
|
|
|
|
|
&& !strncmp (state->buffer, pname, len)
|
|
|
|
|
&& strlen (state->buffer) > strlen (pname)
|
|
|
|
|
&& state->buffer[len] == ':' )
|
|
|
|
|
log_info ("%s\n", state->buffer);
|
|
|
|
|
else
|
|
|
|
|
log_info ("%s%c %s\n",
|
|
|
|
|
pname, state->cont? '+':':', state->buffer);
|
|
|
|
|
}
|
|
|
|
|
state->cont = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
c = es_fgetc (fderr->stream);
|
|
|
|
|
if (c == EOF)
|
|
|
|
|
{
|
|
|
|
|
if (es_feof (fderr->stream))
|
|
|
|
|
{
|
|
|
|
|
fderr->ignore = 1; /* Not anymore needed. */
|
|
|
|
|
}
|
|
|
|
|
else if (es_ferror (fderr->stream))
|
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2015-11-30 12:53:57 +01:00
|
|
|
|
log_error ("error reading stderr of '%s': %s\n",
|
|
|
|
|
state->pgmname, gpg_strerror (err));
|
|
|
|
|
fderr->ignore = 1; /* Disable. */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (c == '\n')
|
|
|
|
|
{
|
|
|
|
|
read_and_log_stderr (state, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (state->used >= sizeof state->buffer - 1)
|
|
|
|
|
{
|
|
|
|
|
read_and_log_stderr (state, NULL);
|
|
|
|
|
state->cont = 1;
|
|
|
|
|
}
|
|
|
|
|
state->buffer[state->used++] = c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-30 14:23:02 +01:00
|
|
|
|
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
2015-11-30 14:23:02 +01:00
|
|
|
|
/* A buffer to copy from one stream to another. */
|
|
|
|
|
struct copy_buffer
|
|
|
|
|
{
|
|
|
|
|
char buffer[4096];
|
|
|
|
|
char *writep;
|
|
|
|
|
size_t nread;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize a copy buffer. */
|
|
|
|
|
static void
|
|
|
|
|
copy_buffer_init (struct copy_buffer *c)
|
|
|
|
|
{
|
|
|
|
|
c->writep = c->buffer;
|
|
|
|
|
c->nread = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Securely wipe a copy buffer. */
|
|
|
|
|
static void
|
|
|
|
|
copy_buffer_shred (struct copy_buffer *c)
|
|
|
|
|
{
|
|
|
|
|
wipememory (c->buffer, sizeof c->buffer);
|
|
|
|
|
c->writep = NULL;
|
|
|
|
|
c->nread = ~0U;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy data from SOURCE to SINK using copy buffer C. */
|
2015-11-30 12:53:57 +01:00
|
|
|
|
static gpg_error_t
|
2015-11-30 14:23:02 +01:00
|
|
|
|
copy_buffer_do_copy (struct copy_buffer *c, estream_t source, estream_t sink)
|
2015-11-30 12:53:57 +01:00
|
|
|
|
{
|
2015-11-30 14:23:02 +01:00
|
|
|
|
gpg_error_t err;
|
|
|
|
|
size_t nwritten;
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
2015-11-30 14:23:02 +01:00
|
|
|
|
if (c->nread == 0)
|
2015-11-30 12:53:57 +01:00
|
|
|
|
{
|
2015-11-30 14:23:02 +01:00
|
|
|
|
c->writep = c->buffer;
|
|
|
|
|
err = es_read (source, c->buffer, sizeof c->buffer, &c->nread);
|
|
|
|
|
if (err)
|
2015-11-30 12:53:57 +01:00
|
|
|
|
{
|
2015-11-30 14:23:02 +01:00
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
|
return 0; /* We will just retry next time. */
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
2015-12-14 19:55:34 +01:00
|
|
|
|
return my_error_from_syserror ();
|
2015-11-30 12:53:57 +01:00
|
|
|
|
}
|
2015-11-30 14:23:02 +01:00
|
|
|
|
|
|
|
|
|
assert (c->nread <= sizeof c->buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->nread == 0)
|
|
|
|
|
return 0; /* Done copying. */
|
|
|
|
|
|
|
|
|
|
err = es_write (sink, c->writep, c->nread, &nwritten);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
|
return 0; /* We will just retry next time. */
|
|
|
|
|
|
2015-12-14 19:55:34 +01:00
|
|
|
|
return my_error_from_syserror ();
|
2015-11-30 12:53:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-30 14:23:02 +01:00
|
|
|
|
assert (nwritten <= c->nread);
|
|
|
|
|
c->writep += nwritten;
|
|
|
|
|
c->nread -= nwritten;
|
|
|
|
|
assert (c->writep - c->buffer <= sizeof c->buffer);
|
|
|
|
|
|
|
|
|
|
if (es_fflush (sink) && errno != EAGAIN)
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2015-11-30 14:23:02 +01:00
|
|
|
|
|
2015-11-30 12:53:57 +01:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-11-30 14:23:02 +01:00
|
|
|
|
/* Flush the remaining data to SINK. */
|
|
|
|
|
static gpg_error_t
|
|
|
|
|
copy_buffer_flush (struct copy_buffer *c, estream_t sink)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
|
|
|
|
|
while (c->nread > 0)
|
|
|
|
|
{
|
|
|
|
|
err = copy_buffer_do_copy (c, NULL, sink);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-30 12:53:57 +01:00
|
|
|
|
/* Run the program PGMNAME with the command line arguments given in
|
2015-11-30 14:23:02 +01:00
|
|
|
|
the NULL terminates array ARGV. If INPUT is not NULL it will be
|
|
|
|
|
fed to stdin of the process. stderr is logged using log_info and
|
|
|
|
|
the process' stdout is written to OUTPUT. On error a diagnostic is
|
|
|
|
|
printed, and an error code returned. */
|
2015-11-30 12:53:57 +01:00
|
|
|
|
gpg_error_t
|
2015-12-14 09:38:46 +01:00
|
|
|
|
gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
|
|
|
|
|
estream_t input,
|
|
|
|
|
estream_t output)
|
2015-11-30 12:53:57 +01:00
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
pid_t pid;
|
|
|
|
|
estream_t infp = NULL;
|
|
|
|
|
estream_t outfp, errfp;
|
|
|
|
|
es_poll_t fds[3];
|
|
|
|
|
int count;
|
|
|
|
|
read_and_log_buffer_t fderrstate;
|
2015-11-30 14:23:02 +01:00
|
|
|
|
struct copy_buffer cpbuf[2];
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
|
|
|
|
memset (fds, 0, sizeof fds);
|
|
|
|
|
memset (&fderrstate, 0, sizeof fderrstate);
|
2015-11-30 14:23:02 +01:00
|
|
|
|
copy_buffer_init (&cpbuf[0]);
|
|
|
|
|
copy_buffer_init (&cpbuf[1]);
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
|
|
|
|
err = gnupg_spawn_process (pgmname, argv, GPG_ERR_SOURCE_DEFAULT,
|
|
|
|
|
NULL, GNUPG_SPAWN_NONBLOCK,
|
2015-11-30 14:23:02 +01:00
|
|
|
|
input? &infp : NULL,
|
2015-11-30 12:53:57 +01:00
|
|
|
|
&outfp, &errfp, &pid);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("error running '%s': %s\n", pgmname, gpg_strerror (err));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fderrstate.pgmname = pgmname;
|
|
|
|
|
|
|
|
|
|
fds[0].stream = infp;
|
|
|
|
|
fds[0].want_write = 1;
|
2015-11-30 14:23:02 +01:00
|
|
|
|
if (!input)
|
2015-11-30 12:53:57 +01:00
|
|
|
|
fds[0].ignore = 1;
|
|
|
|
|
fds[1].stream = outfp;
|
|
|
|
|
fds[1].want_read = 1;
|
|
|
|
|
fds[2].stream = errfp;
|
|
|
|
|
fds[2].want_read = 1;
|
|
|
|
|
/* Now read as long as we have something to poll. We continue
|
|
|
|
|
reading even after EOF or error on stdout so that we get the
|
2015-12-14 09:38:46 +01:00
|
|
|
|
other error messages or remaining outut. */
|
2015-11-30 12:53:57 +01:00
|
|
|
|
while (!fds[1].ignore && !fds[2].ignore)
|
|
|
|
|
{
|
|
|
|
|
count = es_poll (fds, DIM(fds), -1);
|
|
|
|
|
if (count == -1)
|
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2015-11-30 12:53:57 +01:00
|
|
|
|
log_error ("error polling '%s': %s\n", pgmname, gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
if (!count)
|
|
|
|
|
{
|
|
|
|
|
log_debug ("unexpected timeout while polling '%s'\n", pgmname);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fds[0].got_write)
|
|
|
|
|
{
|
2015-11-30 14:23:02 +01:00
|
|
|
|
err = copy_buffer_do_copy (&cpbuf[0], input, fds[0].stream);
|
|
|
|
|
if (err)
|
2015-11-30 12:53:57 +01:00
|
|
|
|
{
|
2015-11-30 14:23:02 +01:00
|
|
|
|
log_error ("error feeding data to '%s': %s\n",
|
|
|
|
|
pgmname, gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
2015-11-30 14:23:02 +01:00
|
|
|
|
if (es_feof (input))
|
2015-11-30 12:53:57 +01:00
|
|
|
|
{
|
2015-11-30 14:23:02 +01:00
|
|
|
|
err = copy_buffer_flush (&cpbuf[0], fds[0].stream);
|
|
|
|
|
if (err)
|
2015-11-30 12:53:57 +01:00
|
|
|
|
{
|
2015-11-30 14:23:02 +01:00
|
|
|
|
log_error ("error feeding data to '%s': %s\n",
|
|
|
|
|
pgmname, gpg_strerror (err));
|
|
|
|
|
goto leave;
|
2015-11-30 12:53:57 +01:00
|
|
|
|
}
|
2015-11-30 14:23:02 +01:00
|
|
|
|
|
2015-11-30 12:53:57 +01:00
|
|
|
|
fds[0].ignore = 1; /* ready. */
|
|
|
|
|
es_fclose (infp); infp = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fds[1].got_read)
|
2015-11-30 14:23:02 +01:00
|
|
|
|
{
|
|
|
|
|
err = copy_buffer_do_copy (&cpbuf[1], fds[1].stream, output);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("error reading data from '%s': %s\n",
|
|
|
|
|
pgmname, gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-30 12:53:57 +01:00
|
|
|
|
if (fds[2].got_read)
|
|
|
|
|
read_and_log_stderr (&fderrstate, fds + 2);
|
2015-11-30 14:23:02 +01:00
|
|
|
|
}
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
2015-11-30 14:23:02 +01:00
|
|
|
|
err = copy_buffer_flush (&cpbuf[1], output);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("error reading data from '%s': %s\n",
|
|
|
|
|
pgmname, gpg_strerror (err));
|
|
|
|
|
goto leave;
|
2015-11-30 12:53:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
read_and_log_stderr (&fderrstate, NULL); /* Flush. */
|
|
|
|
|
es_fclose (infp); infp = NULL;
|
|
|
|
|
es_fclose (outfp); outfp = NULL;
|
|
|
|
|
es_fclose (errfp); errfp = NULL;
|
|
|
|
|
|
|
|
|
|
err = gnupg_wait_process (pgmname, pid, 1, NULL);
|
|
|
|
|
pid = (pid_t)(-1);
|
|
|
|
|
|
|
|
|
|
leave:
|
|
|
|
|
if (err)
|
2015-11-30 14:23:02 +01:00
|
|
|
|
gnupg_kill_process (pid);
|
2015-11-30 12:53:57 +01:00
|
|
|
|
|
|
|
|
|
es_fclose (infp);
|
|
|
|
|
es_fclose (outfp);
|
|
|
|
|
es_fclose (errfp);
|
|
|
|
|
if (pid != (pid_t)(-1))
|
|
|
|
|
gnupg_wait_process (pgmname, pid, 1, NULL);
|
|
|
|
|
gnupg_release_process (pid);
|
|
|
|
|
|
2015-11-30 14:23:02 +01:00
|
|
|
|
copy_buffer_shred (&cpbuf[0]);
|
|
|
|
|
copy_buffer_shred (&cpbuf[1]);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* A dummy free function to pass to 'es_mopen'. */
|
|
|
|
|
static void
|
|
|
|
|
nop_free (void *ptr)
|
|
|
|
|
{
|
|
|
|
|
(void) ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Run the program PGMNAME with the command line arguments given in
|
|
|
|
|
the NULL terminates array ARGV. If INPUT_STRING is not NULL it
|
|
|
|
|
will be fed to stdin of the process. stderr is logged using
|
|
|
|
|
log_info and the process' stdout is returned in a newly malloced
|
|
|
|
|
buffer RESULT with the length stored at RESULTLEN if not given as
|
|
|
|
|
NULL. A hidden Nul is appended to the output. On error NULL is
|
|
|
|
|
stored at RESULT, a diagnostic is printed, and an error code
|
|
|
|
|
returned. */
|
|
|
|
|
gpg_error_t
|
2015-12-14 09:38:46 +01:00
|
|
|
|
gnupg_exec_tool (const char *pgmname, const char *argv[],
|
|
|
|
|
const char *input_string,
|
|
|
|
|
char **result, size_t *resultlen)
|
2015-11-30 14:23:02 +01:00
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
estream_t input = NULL;
|
|
|
|
|
estream_t output;
|
|
|
|
|
size_t len;
|
|
|
|
|
size_t nread;
|
|
|
|
|
|
|
|
|
|
*result = NULL;
|
|
|
|
|
if (resultlen)
|
|
|
|
|
*resultlen = 0;
|
|
|
|
|
|
|
|
|
|
if (input_string)
|
|
|
|
|
{
|
|
|
|
|
len = strlen (input_string);
|
|
|
|
|
input = es_mopen ((char *) input_string, len, len,
|
|
|
|
|
0 /* don't grow */, NULL, nop_free, "rb");
|
|
|
|
|
if (! input)
|
2015-12-14 19:55:34 +01:00
|
|
|
|
return my_error_from_syserror ();
|
2015-11-30 14:23:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output = es_fopenmem (0, "wb");
|
|
|
|
|
if (! output)
|
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2015-11-30 14:23:02 +01:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-14 09:38:46 +01:00
|
|
|
|
err = gnupg_exec_tool_stream (pgmname, argv, input, output);
|
2015-11-30 14:23:02 +01:00
|
|
|
|
if (err)
|
|
|
|
|
goto leave;
|
|
|
|
|
|
|
|
|
|
len = es_ftello (output);
|
|
|
|
|
err = es_fseek (output, 0, SEEK_SET);
|
|
|
|
|
if (err)
|
|
|
|
|
goto leave;
|
|
|
|
|
|
2016-02-02 18:18:31 +01:00
|
|
|
|
*result = xtrymalloc (len + 1);
|
|
|
|
|
if (!*result)
|
2015-11-30 14:23:02 +01:00
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2015-11-30 14:23:02 +01:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 18:18:31 +01:00
|
|
|
|
if (len)
|
2015-11-30 14:23:02 +01:00
|
|
|
|
{
|
2016-02-02 18:18:31 +01:00
|
|
|
|
err = es_read (output, *result, len, &nread);
|
|
|
|
|
if (err)
|
|
|
|
|
goto leave;
|
|
|
|
|
if (nread != len)
|
|
|
|
|
log_fatal ("%s: short read from memstream\n", __func__);
|
2015-11-30 14:23:02 +01:00
|
|
|
|
}
|
2016-02-02 18:18:31 +01:00
|
|
|
|
(*result)[len] = 0;
|
|
|
|
|
|
|
|
|
|
if (resultlen)
|
|
|
|
|
*resultlen = len;
|
2015-11-30 14:23:02 +01:00
|
|
|
|
|
|
|
|
|
leave:
|
2016-02-02 18:18:31 +01:00
|
|
|
|
es_fclose (input);
|
2015-11-30 14:23:02 +01:00
|
|
|
|
es_fclose (output);
|
2016-02-02 18:18:31 +01:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
xfree (*result);
|
|
|
|
|
*result = NULL;
|
|
|
|
|
}
|
2015-11-30 12:53:57 +01:00
|
|
|
|
return err;
|
|
|
|
|
}
|