core: Replace all calls to *sprintf by gpgrt_*sprintf.
* configure.ac (vasprintf): Remove check. * src/vasprintf.c: Remove file. * src/util.h (vasprintf, asprintf): Remove prototypes. Replace all calls to vasprintf and asprintf by gpgrt_vasprintf or gpgrt_asprintf. Also take care to use gpgrt_free on the returned value. * src/w32-util.c (_gpgme_get_gpgconf_path): Replace a gpgrt_asprintf by _gpgme_strconcat. (snprintf): New macro to use gpgrt_snprintf instead of the system's standard snprintf. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
563420a88f
commit
15050ce5fc
@ -632,11 +632,6 @@ AC_MSG_NOTICE([checking for libraries])
|
||||
|
||||
AC_FUNC_FSEEKO
|
||||
|
||||
AC_REPLACE_FUNCS(vasprintf)
|
||||
if test "$ac_cv_func_vasprintf" != yes; then
|
||||
GNUPG_CHECK_VA_COPY
|
||||
fi
|
||||
|
||||
# Try to find a thread-safe version of ttyname().
|
||||
gnupg_REPLACE_TTYNAME_R
|
||||
if test "$ac_cv_func_ttyname_r" != yes; then
|
||||
|
14
src/debug.c
14
src/debug.c
@ -313,7 +313,7 @@ _gpgme_debug_begin (void **line, int level, const char *format, ...)
|
||||
}
|
||||
|
||||
va_start (arg_ptr, format);
|
||||
res = vasprintf ((char **) line, format, arg_ptr);
|
||||
res = gpgrt_vasprintf ((char **) line, format, arg_ptr);
|
||||
va_end (arg_ptr);
|
||||
if (res < 0)
|
||||
*line = NULL;
|
||||
@ -333,16 +333,16 @@ _gpgme_debug_add (void **line, const char *format, ...)
|
||||
return;
|
||||
|
||||
va_start (arg_ptr, format);
|
||||
res = vasprintf (&toadd, format, arg_ptr);
|
||||
res = gpgrt_vasprintf (&toadd, format, arg_ptr);
|
||||
va_end (arg_ptr);
|
||||
if (res < 0)
|
||||
{
|
||||
free (*line);
|
||||
gpgrt_free (*line);
|
||||
*line = NULL;
|
||||
}
|
||||
res = asprintf (&result, "%s%s", *(char **) line, toadd);
|
||||
free (toadd);
|
||||
free (*line);
|
||||
res = gpgrt_asprintf (&result, "%s%s", *(char **) line, toadd);
|
||||
gpgrt_free (toadd);
|
||||
gpgrt_free (*line);
|
||||
if (res < 0)
|
||||
*line = NULL;
|
||||
else
|
||||
@ -361,7 +361,7 @@ _gpgme_debug_end (void **line)
|
||||
/* The smallest possible level is 1, so force logging here by
|
||||
using that. */
|
||||
_gpgme_debug (1, "%s", *line);
|
||||
free (*line);
|
||||
gpgrt_free (*line);
|
||||
*line = NULL;
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ llass_new (void **engine, const char *file_name, const char *home_dir,
|
||||
goto leave;
|
||||
if (dft_display)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free (dft_display);
|
||||
@ -275,7 +275,7 @@ llass_new (void **engine, const char *file_name, const char *home_dir,
|
||||
|
||||
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
}
|
||||
@ -304,14 +304,14 @@ llass_new (void **engine, const char *file_name, const char *home_dir,
|
||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||
if (!rc)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
goto leave;
|
||||
}
|
||||
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
@ -320,7 +320,7 @@ llass_new (void **engine, const char *file_name, const char *home_dir,
|
||||
goto leave;
|
||||
if (dft_ttytype)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype)< 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free (dft_ttytype);
|
||||
@ -330,7 +330,7 @@ llass_new (void **engine, const char *file_name, const char *home_dir,
|
||||
|
||||
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
}
|
||||
@ -408,13 +408,13 @@ llass_set_locale (void *engine, int category, const char *value)
|
||||
if (!value)
|
||||
return 0;
|
||||
|
||||
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
|
||||
err = gpg_error_from_syserror ();
|
||||
else
|
||||
{
|
||||
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir,
|
||||
goto leave;
|
||||
if (dft_display)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
|
||||
{
|
||||
free (dft_display);
|
||||
err = gpg_error_from_syserror ();
|
||||
@ -280,7 +280,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir,
|
||||
|
||||
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
}
|
||||
@ -304,14 +304,14 @@ g13_new (void **engine, const char *file_name, const char *home_dir,
|
||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||
if (!rc)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
goto leave;
|
||||
}
|
||||
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
@ -320,7 +320,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir,
|
||||
goto leave;
|
||||
if (dft_ttytype)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype)< 0)
|
||||
{
|
||||
free (dft_ttytype);
|
||||
err = gpg_error_from_syserror ();
|
||||
@ -330,7 +330,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir,
|
||||
|
||||
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
}
|
||||
@ -400,13 +400,13 @@ g13_set_locale (void *engine, int category, const char *value)
|
||||
if (!value)
|
||||
return 0;
|
||||
|
||||
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
|
||||
err = gpg_error_from_syserror ();
|
||||
else
|
||||
{
|
||||
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -74,6 +74,10 @@ struct fd_data_map_s
|
||||
};
|
||||
|
||||
|
||||
/* NB.: R_LINE is allocated an gpgrt function and thus gpgrt_free
|
||||
* shall be used to release it. This takes care of custom memory
|
||||
* allocators and avoids problems on Windows with different runtimes
|
||||
* used for libgpg-error/gpgrt and gpgme. */
|
||||
typedef gpgme_error_t (*colon_preprocessor_t) (char *line, char **rline);
|
||||
|
||||
struct engine_gpg
|
||||
@ -1346,7 +1350,7 @@ read_colon_line (engine_gpg_t gpg)
|
||||
}
|
||||
while (linep && *linep);
|
||||
|
||||
free (line);
|
||||
gpgrt_free (line);
|
||||
}
|
||||
else
|
||||
gpg->colon.fnc (gpg->colon.fnc_value, buffer);
|
||||
@ -2513,7 +2517,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
|
||||
n = strlen (field[1]);
|
||||
if (n > 16)
|
||||
{
|
||||
if (asprintf (r_line,
|
||||
if (gpgrt_asprintf (r_line,
|
||||
"pub:o%s:%s:%s:%s:%s:%s::::::::\n"
|
||||
"fpr:::::::::%s:",
|
||||
field[6], field[3], field[2], field[1] + n - 16,
|
||||
@ -2522,7 +2526,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (asprintf (r_line,
|
||||
if (gpgrt_asprintf (r_line,
|
||||
"pub:o%s:%s:%s:%s:%s:%s::::::::",
|
||||
field[6], field[3], field[2], field[1],
|
||||
field[4], field[5]) < 0)
|
||||
@ -2580,7 +2584,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
if (asprintf (r_line, "uid:o%s::::%s:%s:::%s:",
|
||||
if (gpgrt_asprintf (r_line, "uid:o%s::::%s:%s:::%s:",
|
||||
field[4], field[2], field[3], uid) < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir,
|
||||
goto leave;
|
||||
if (dft_display)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
|
||||
{
|
||||
free (dft_display);
|
||||
err = gpg_error_from_syserror ();
|
||||
@ -406,7 +406,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir,
|
||||
|
||||
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
}
|
||||
@ -430,14 +430,14 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir,
|
||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||
if (!rc)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
goto leave;
|
||||
}
|
||||
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
@ -446,7 +446,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir,
|
||||
goto leave;
|
||||
if (dft_ttytype)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype)< 0)
|
||||
{
|
||||
free (dft_ttytype);
|
||||
err = gpg_error_from_syserror ();
|
||||
@ -456,7 +456,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir,
|
||||
|
||||
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
}
|
||||
@ -561,13 +561,13 @@ gpgsm_set_locale (void *engine, int category, const char *value)
|
||||
if (!value)
|
||||
return 0;
|
||||
|
||||
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
|
||||
err = gpg_error_from_syserror ();
|
||||
else
|
||||
{
|
||||
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
}
|
||||
|
||||
return err;
|
||||
@ -1642,10 +1642,10 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only,
|
||||
gpgsm_assuan_simple_command (gpgsm, "GETINFO agent-check", NULL, NULL);
|
||||
|
||||
/* Always send list-mode option because RESET does not reset it. */
|
||||
if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
|
||||
if (gpgrt_asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
err = gpgsm_assuan_simple_command (gpgsm, line, NULL, NULL);
|
||||
free (line);
|
||||
gpgrt_free (line);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -1726,10 +1726,10 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
|
||||
list_mode |= 2;
|
||||
|
||||
/* Always send list-mode option because RESET does not reset it. */
|
||||
if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
|
||||
if (gpgrt_asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
err = gpgsm_assuan_simple_command (gpgsm, line, NULL, NULL);
|
||||
free (line);
|
||||
gpgrt_free (line);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -1860,10 +1860,11 @@ gpgsm_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
|
||||
can reset any previously set value in case the default is
|
||||
requested. */
|
||||
|
||||
if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0)
|
||||
if (gpgrt_asprintf (&assuan_cmd,
|
||||
"OPTION include-certs %i", include_certs) < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
err = gpgsm_assuan_simple_command (gpgsm, assuan_cmd, NULL, NULL);
|
||||
free (assuan_cmd);
|
||||
gpgrt_free (assuan_cmd);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
@ -2048,7 +2049,7 @@ gpgsm_passwd (void *engine, gpgme_key_t key, unsigned int flags)
|
||||
if (!key || !key->subkeys || !key->subkeys->fpr)
|
||||
return gpg_error (GPG_ERR_INV_CERT_OBJ);
|
||||
|
||||
if (asprintf (&line, "PASSWD -- %s", key->subkeys->fpr) < 0)
|
||||
if (gpgrt_asprintf (&line, "PASSWD -- %s", key->subkeys->fpr) < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
|
||||
gpgsm_clear_fd (gpgsm, OUTPUT_FD);
|
||||
@ -2057,7 +2058,7 @@ gpgsm_passwd (void *engine, gpgme_key_t key, unsigned int flags)
|
||||
gpgsm->inline_data = NULL;
|
||||
|
||||
err = start (gpgsm, line);
|
||||
free (line);
|
||||
gpgrt_free (line);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir,
|
||||
goto leave;
|
||||
if (dft_display)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free (dft_display);
|
||||
@ -326,7 +326,7 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir,
|
||||
|
||||
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
}
|
||||
@ -350,14 +350,14 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir,
|
||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||
if (!rc)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
goto leave;
|
||||
}
|
||||
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
@ -366,7 +366,7 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir,
|
||||
goto leave;
|
||||
if (dft_ttytype)
|
||||
{
|
||||
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype)< 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free (dft_ttytype);
|
||||
@ -376,7 +376,7 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir,
|
||||
|
||||
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
if (err)
|
||||
goto leave;
|
||||
}
|
||||
@ -441,13 +441,13 @@ uiserver_set_locale (void *engine, int category, const char *value)
|
||||
if (!value)
|
||||
return 0;
|
||||
|
||||
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
|
||||
if (gpgrt_asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
|
||||
err = gpg_error_from_syserror ();
|
||||
else
|
||||
{
|
||||
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
free (optstr);
|
||||
gpgrt_free (optstr);
|
||||
}
|
||||
|
||||
return err;
|
||||
@ -982,7 +982,7 @@ _uiserver_decrypt (void *engine, int verify,
|
||||
else
|
||||
return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
|
||||
|
||||
if (asprintf (&cmd, "DECRYPT%s%s%s", protocol,
|
||||
if (gpgrt_asprintf (&cmd, "DECRYPT%s%s%s", protocol,
|
||||
verify ? "" : " --no-verify",
|
||||
export_session_key ? " --export-session-key" : "") < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
@ -992,20 +992,20 @@ _uiserver_decrypt (void *engine, int verify,
|
||||
map_data_enc (uiserver->input_cb.data));
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return gpg_error (GPG_ERR_GENERAL); /* FIXME */
|
||||
}
|
||||
uiserver->output_cb.data = plain;
|
||||
err = uiserver_set_fd (uiserver, OUTPUT_FD, 0);
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return gpg_error (GPG_ERR_GENERAL); /* FIXME */
|
||||
}
|
||||
uiserver->inline_data = NULL;
|
||||
|
||||
err = start (engine, cmd);
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -1114,7 +1114,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
|
||||
if (!recp || plain || ciph)
|
||||
return gpg_error (GPG_ERR_INV_VALUE);
|
||||
|
||||
if (asprintf (&cmd, "PREP_ENCRYPT%s%s", protocol,
|
||||
if (gpgrt_asprintf (&cmd, "PREP_ENCRYPT%s%s", protocol,
|
||||
(flags & GPGME_ENCRYPT_EXPECT_SIGN)
|
||||
? " --expect-sign" : "") < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
@ -1124,7 +1124,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
|
||||
if (!plain || !ciph)
|
||||
return gpg_error (GPG_ERR_INV_VALUE);
|
||||
|
||||
if (asprintf (&cmd, "ENCRYPT%s", protocol) < 0)
|
||||
if (gpgrt_asprintf (&cmd, "ENCRYPT%s", protocol) < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
|
||||
@ -1135,7 +1135,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
|
||||
map_data_enc (uiserver->input_cb.data));
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@ -1147,7 +1147,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
|
||||
: map_data_enc (uiserver->output_cb.data));
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@ -1159,13 +1159,13 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
|
||||
err = set_recipients (uiserver, recp);
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
err = start (uiserver, cmd);
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -1195,7 +1195,7 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
|
||||
else
|
||||
return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
|
||||
|
||||
if (asprintf (&cmd, "SIGN%s%s", protocol,
|
||||
if (gpgrt_asprintf (&cmd, "SIGN%s%s", protocol,
|
||||
(mode == GPGME_SIG_MODE_DETACH) ? " --detached" : "") < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
|
||||
@ -1220,10 +1220,10 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
|
||||
err = gpg_error (GPG_ERR_INV_VALUE);
|
||||
gpgme_key_unref (key);
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
uiserver->input_cb.data = in;
|
||||
@ -1231,7 +1231,7 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
|
||||
map_data_enc (uiserver->input_cb.data));
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
uiserver->output_cb.data = out;
|
||||
@ -1239,13 +1239,13 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
|
||||
: map_data_enc (uiserver->output_cb.data));
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
uiserver->inline_data = NULL;
|
||||
|
||||
err = start (uiserver, cmd);
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -1274,7 +1274,7 @@ uiserver_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
|
||||
else
|
||||
return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
|
||||
|
||||
if (asprintf (&cmd, "VERIFY%s", protocol) < 0)
|
||||
if (gpgrt_asprintf (&cmd, "VERIFY%s", protocol) < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
|
||||
uiserver->input_cb.data = sig;
|
||||
@ -1282,7 +1282,7 @@ uiserver_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
|
||||
map_data_enc (uiserver->input_cb.data));
|
||||
if (err)
|
||||
{
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
if (plaintext)
|
||||
@ -1302,7 +1302,7 @@ uiserver_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
|
||||
if (!err)
|
||||
err = start (uiserver, cmd);
|
||||
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
11
src/util.h
11
src/util.h
@ -95,11 +95,12 @@ _gpgme_stpcpy (char *a, const char *b)
|
||||
#define stpcpy(a,b) _gpgme_stpcpy ((a), (b))
|
||||
#endif /*!HAVE_STPCPY*/
|
||||
|
||||
#if !HAVE_VASPRINTF
|
||||
#include <stdarg.h>
|
||||
int vasprintf (char **result, const char *format, va_list args);
|
||||
int asprintf (char **result, const char *format, ...);
|
||||
#endif
|
||||
|
||||
/* Due to a bug in mingw32's snprintf related to the 'l' modifier and
|
||||
for increased portability we use our snprintf on all systems. */
|
||||
#undef snprintf
|
||||
#define snprintf gpgrt_snprintf
|
||||
|
||||
|
||||
#if REPLACE_TTYNAME_R
|
||||
int _gpgme_ttyname_r (int fd, char *buf, size_t buflen);
|
||||
|
206
src/vasprintf.c
206
src/vasprintf.c
@ -1,206 +0,0 @@
|
||||
/* Like vsprintf but provides a pointer to malloc'd storage, which must
|
||||
be freed by the caller.
|
||||
Copyright (C) 1994, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the libiberty library.
|
||||
Libiberty is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
Libiberty is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with libiberty; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#ifndef va_copy /* According to POSIX, va_copy is a macro. */
|
||||
#if defined (__GNUC__) && defined (__PPC__) \
|
||||
&& (defined (_CALL_SYSV) || defined (_WIN32))
|
||||
#define va_copy(d, s) (*(d) = *(s))
|
||||
#elif defined (MUST_COPY_VA_BYVAL)
|
||||
#define va_copy(d, s) ((d) = (s))
|
||||
#else
|
||||
#define va_copy(d, s) memcpy ((d), (s), sizeof (va_list))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
int global_total_width;
|
||||
#endif
|
||||
|
||||
static int int_vasprintf (char **, const char *, va_list *);
|
||||
|
||||
static int
|
||||
int_vasprintf (result, format, args)
|
||||
char **result;
|
||||
const char *format;
|
||||
va_list *args;
|
||||
{
|
||||
#ifdef HAVE_W32CE_SYSTEM
|
||||
/* No va_copy and the replacement above doesn't work. */
|
||||
#define MAX_STRLEN 256
|
||||
*result = malloc (MAX_STRLEN);
|
||||
if (*result != NULL)
|
||||
{
|
||||
int res = _vsnprintf (*result, MAX_STRLEN, format, *args);
|
||||
(*result)[MAX_STRLEN - 1] = '\0';
|
||||
return res;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
#else
|
||||
const char *p = format;
|
||||
/* Add one to make sure that it is never zero, which might cause malloc
|
||||
to return NULL. */
|
||||
int total_width = strlen (format) + 1;
|
||||
va_list ap;
|
||||
|
||||
va_copy (ap, *args);
|
||||
|
||||
while (*p != '\0')
|
||||
{
|
||||
if (*p++ == '%')
|
||||
{
|
||||
while (strchr ("-+ #0", *p))
|
||||
++p;
|
||||
if (*p == '*')
|
||||
{
|
||||
++p;
|
||||
total_width += abs (va_arg (ap, int));
|
||||
}
|
||||
else
|
||||
total_width += strtoul (p, (char **) &p, 10);
|
||||
if (*p == '.')
|
||||
{
|
||||
++p;
|
||||
if (*p == '*')
|
||||
{
|
||||
++p;
|
||||
total_width += abs (va_arg (ap, int));
|
||||
}
|
||||
else
|
||||
total_width += strtoul (p, (char **) &p, 10);
|
||||
}
|
||||
while (strchr ("hlL", *p))
|
||||
++p;
|
||||
/* Should be big enough for any format specifier except %s and floats. */
|
||||
total_width += 30;
|
||||
switch (*p)
|
||||
{
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 'c':
|
||||
(void) va_arg (ap, int);
|
||||
break;
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
(void) va_arg (ap, double);
|
||||
/* Since an ieee double can have an exponent of 307, we'll
|
||||
make the buffer wide enough to cover the gross case. */
|
||||
total_width += 307;
|
||||
break;
|
||||
case 's':
|
||||
{
|
||||
char *tmp = va_arg (ap, char *);
|
||||
if (tmp)
|
||||
total_width += strlen (tmp);
|
||||
else /* in case the vsprintf does prints a text */
|
||||
total_width += 25; /* e.g. "(null pointer reference)" */
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
case 'n':
|
||||
(void) va_arg (ap, char *);
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
#ifdef TEST
|
||||
global_total_width = total_width;
|
||||
#endif
|
||||
*result = malloc (total_width);
|
||||
if (*result != NULL)
|
||||
return vsprintf (*result, format, *args);
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
vasprintf (result, format, args)
|
||||
char **result;
|
||||
const char *format;
|
||||
#if defined (_BSD_VA_LIST_) && defined (__FreeBSD__)
|
||||
_BSD_VA_LIST_ args;
|
||||
#else
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
return int_vasprintf (result, format, &args);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
asprintf (char **buf, const char *fmt, ...)
|
||||
{
|
||||
int status;
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, fmt);
|
||||
status = vasprintf (buf, fmt, ap);
|
||||
va_end (ap);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
void
|
||||
checkit (const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *result;
|
||||
|
||||
va_start (args, format);
|
||||
vasprintf (&result, format, args);
|
||||
if (strlen (result) < global_total_width)
|
||||
printf ("PASS: ");
|
||||
else
|
||||
printf ("FAIL: ");
|
||||
printf ("%d %s\n", global_total_width, result);
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
checkit ("%d", 0x12345678);
|
||||
checkit ("%200d", 5);
|
||||
checkit ("%.300d", 6);
|
||||
checkit ("%100.150d", 7);
|
||||
checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
|
||||
777777777777777777333333333333366666666666622222222222777777777777733333");
|
||||
checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx");
|
||||
}
|
||||
#endif /* TEST */
|
@ -138,7 +138,7 @@ _gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
|
||||
return gpg_error (GPG_ERR_UNUSABLE_PUBKEY);
|
||||
}
|
||||
|
||||
if (asprintf (&cmd, "RECIPIENT %s", recp[i]->subkeys->fpr) < 0)
|
||||
if (gpgrt_asprintf (&cmd, "RECIPIENT %s", recp[i]->subkeys->fpr) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free (container_file_esc);
|
||||
@ -147,7 +147,7 @@ _gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
|
||||
|
||||
err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, op_err);
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
if (err || *op_err)
|
||||
{
|
||||
free (container_file_esc);
|
||||
@ -156,7 +156,7 @@ _gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
|
||||
recp++;
|
||||
}
|
||||
|
||||
if (asprintf (&cmd, "CREATE -- %s", container_file_esc) < 0)
|
||||
if (gpgrt_asprintf (&cmd, "CREATE -- %s", container_file_esc) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free (container_file_esc);
|
||||
@ -166,7 +166,7 @@ _gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
|
||||
|
||||
err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, op_err);
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ _gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (asprintf (&cmd, "OPEN -- %s", container_file_esc) < 0)
|
||||
if (gpgrt_asprintf (&cmd, "OPEN -- %s", container_file_esc) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free (container_file_esc);
|
||||
@ -194,7 +194,7 @@ _gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
|
||||
|
||||
err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, op_err);
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
if (err || *op_err)
|
||||
return err;
|
||||
|
||||
@ -206,7 +206,7 @@ _gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (asprintf (&cmd, "MOUNT -- %s", mount_dir_esc) < 0)
|
||||
if (gpgrt_asprintf (&cmd, "MOUNT -- %s", mount_dir_esc) < 0)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free (mount_dir_esc);
|
||||
@ -216,13 +216,13 @@ _gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (asprintf (&cmd, "MOUNT") < 0)
|
||||
if (gpgrt_asprintf (&cmd, "MOUNT") < 0)
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
|
||||
err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
|
||||
_gpgme_vfs_mount_status_handler, ctx, op_err);
|
||||
free (cmd);
|
||||
gpgrt_free (cmd);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -1643,11 +1643,11 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
|
||||
"with your installation.\n"
|
||||
"Please report the problem to your "
|
||||
"distributor of GpgME.\n\n"
|
||||
"Developers Note: The install dir can be "
|
||||
"Developer's Note: The install dir can be "
|
||||
"manually set with: gpgme_set_global_flag",
|
||||
_gpgme_get_inst_dir ());
|
||||
MessageBoxA (NULL, msg, "GpgME not installed correctly", MB_OK);
|
||||
free (msg);
|
||||
gpgrt_free (msg);
|
||||
gpg_err_set_errno (EIO);
|
||||
return TRACE_SYSRES (-1);
|
||||
}
|
||||
|
@ -577,9 +577,10 @@ _gpgme_get_gpgconf_path (void)
|
||||
"Install Directory");
|
||||
if (tmp)
|
||||
{
|
||||
if (gpgrt_asprintf (&dir, "%s\\bin", tmp) == -1)
|
||||
return NULL;
|
||||
dir = _gpgme_strconcat (tmp, "\\bin", NULL);
|
||||
free (tmp);
|
||||
if (!dir)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (dir)
|
||||
|
Loading…
Reference in New Issue
Block a user