summaryrefslogtreecommitdiffstats
path: root/agent
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2008-05-27 14:03:50 +0200
committerWerner Koch <wk@gnupg.org>2008-05-27 14:03:50 +0200
commit138bf2dc1552fe8b8a1da6edcbd9fdcb747a73b9 (patch)
tree2dd4b1c251b4802660287496b4fd688bb4d7e0c5 /agent
parentMinor bug fixes and document new gpg-connect-feature. (diff)
downloadgnupg2-138bf2dc1552fe8b8a1da6edcbd9fdcb747a73b9.tar.xz
gnupg2-138bf2dc1552fe8b8a1da6edcbd9fdcb747a73b9.zip
Fixed segv in gpg-agent (command marktrusted).
Replaced almost all free by xfree. Translation fixes.
Diffstat (limited to 'agent')
-rw-r--r--agent/ChangeLog27
-rw-r--r--agent/call-pinentry.c4
-rw-r--r--agent/command-ssh.c4
-rw-r--r--agent/command.c30
-rw-r--r--agent/divert-scd.c4
-rw-r--r--agent/gpg-agent.c64
-rw-r--r--agent/preset-passphrase.c4
-rw-r--r--agent/trustlist.c18
-rw-r--r--agent/w32main.c4
9 files changed, 100 insertions, 59 deletions
diff --git a/agent/ChangeLog b/agent/ChangeLog
index d48d13a7e..4d72a5a58 100644
--- a/agent/ChangeLog
+++ b/agent/ChangeLog
@@ -1,3 +1,30 @@
+2008-05-27 Werner Koch <wk@g10code.com>
+
+ * trustlist.c (insert_colons): Fix stupidly wrong allocation
+ computation.
+
+2008-05-26 Werner Koch <wk@g10code.com>
+
+ * gpg-agent.c (main): Re-initialize default assuan log stream if a
+ log file is used.
+
+ * trustlist.c (agent_marktrusted): Use xtryasprintf and xfree.
+
+ * gpg-agent.c (main, agent_deinit_default_ctrl): Always use xfree
+ because our asprintf is mapped to an xmalloc style function in
+ util.h. Replace xtrdup by xtrystrdup.
+ * w32main.c (build_argv): Ditto.
+ * preset-passphrase.c (preset_passphrase): Ditto.
+ * divert-scd.c (ask_for_card): Ditto.
+ * command.c (option_handler): Ditto.
+ * command-ssh.c (ssh_handler_request_identities): Ditto.
+ * call-pinentry.c (start_pinentry): Ditto.
+
+ * gpg-agent.c (start_connection_thread)
+ (start_connection_thread_ssh): Use pth_thread_id for useful output
+ under W32.
+ (pth_thread_id) [!PTH_HAVE_PTH_THREAD_ID]: New.
+
2008-03-17 Werner Koch <wk@g10code.com>
* agent.h (agent_inq_pinentry_launched): New prototype.
diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c
index 6ae31030d..ea18d43dd 100644
--- a/agent/call-pinentry.c
+++ b/agent/call-pinentry.c
@@ -319,7 +319,7 @@ start_pinentry (ctrl_t ctrl)
return unlock_pinentry (out_of_core ());
rc = assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
NULL);
- free (optstr);
+ xfree (optstr);
if (rc)
return unlock_pinentry (rc);
}
@@ -373,7 +373,7 @@ start_pinentry (ctrl_t ctrl)
{
assuan_transact (entry_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
NULL);
- free (optstr);
+ xfree (optstr);
}
}
diff --git a/agent/command-ssh.c b/agent/command-ssh.c
index 9e2a57d6f..527b9e2aa 100644
--- a/agent/command-ssh.c
+++ b/agent/command-ssh.c
@@ -1960,7 +1960,7 @@ ssh_handler_request_identities (ctrl_t ctrl,
if (ctrl_fp)
fclose (ctrl_fp);
- free (key_directory);
+ xfree (key_directory);
xfree (key_path);
xfree (buffer);
xfree (key_type);
@@ -2430,7 +2430,7 @@ ssh_identity_register (ctrl_t ctrl, gcry_sexp_t key, int ttl)
xfree (pi);
xfree (buffer);
xfree (comment);
- free (description); /* (asprintf allocated, thus regular free.) */
+ xfree (description);
return err;
}
diff --git a/agent/command.c b/agent/command.c
index 720272904..92e12e22c 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -1422,8 +1422,8 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
if (!strcmp (key, "display"))
{
if (ctrl->display)
- free (ctrl->display);
- ctrl->display = strdup (value);
+ xfree (ctrl->display);
+ ctrl->display = xtrystrdup (value);
if (!ctrl->display)
return out_of_core ();
}
@@ -1432,8 +1432,8 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
if (!opt.keep_tty)
{
if (ctrl->ttyname)
- free (ctrl->ttyname);
- ctrl->ttyname = strdup (value);
+ xfree (ctrl->ttyname);
+ ctrl->ttyname = xtrystrdup (value);
if (!ctrl->ttyname)
return out_of_core ();
}
@@ -1443,8 +1443,8 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
if (!opt.keep_tty)
{
if (ctrl->ttytype)
- free (ctrl->ttytype);
- ctrl->ttytype = strdup (value);
+ xfree (ctrl->ttytype);
+ ctrl->ttytype = xtrystrdup (value);
if (!ctrl->ttytype)
return out_of_core ();
}
@@ -1452,32 +1452,32 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
else if (!strcmp (key, "lc-ctype"))
{
if (ctrl->lc_ctype)
- free (ctrl->lc_ctype);
- ctrl->lc_ctype = strdup (value);
+ xfree (ctrl->lc_ctype);
+ ctrl->lc_ctype = xtrystrdup (value);
if (!ctrl->lc_ctype)
return out_of_core ();
}
else if (!strcmp (key, "lc-messages"))
{
if (ctrl->lc_messages)
- free (ctrl->lc_messages);
- ctrl->lc_messages = strdup (value);
+ xfree (ctrl->lc_messages);
+ ctrl->lc_messages = xtrystrdup (value);
if (!ctrl->lc_messages)
return out_of_core ();
}
else if (!strcmp (key, "xauthority"))
{
if (ctrl->xauthority)
- free (ctrl->xauthority);
- ctrl->xauthority = strdup (value);
+ xfree (ctrl->xauthority);
+ ctrl->xauthority = xtrystrdup (value);
if (!ctrl->xauthority)
return out_of_core ();
}
else if (!strcmp (key, "pinentry-user-data"))
{
if (ctrl->pinentry_user_data)
- free (ctrl->pinentry_user_data);
- ctrl->pinentry_user_data = strdup (value);
+ xfree (ctrl->pinentry_user_data);
+ ctrl->pinentry_user_data = xtrystrdup (value);
if (!ctrl->pinentry_user_data)
return out_of_core ();
}
@@ -1515,7 +1515,7 @@ io_monitor (assuan_context_t ctx, int direction,
const char *line, size_t linelen)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
-
+
/* Note that we only check for the uppercase name. This allows to
see the logging for debugging if using a non-upercase command
name. */
diff --git a/agent/divert-scd.c b/agent/divert-scd.c
index 25207331f..eac3b59c3 100644
--- a/agent/divert-scd.c
+++ b/agent/divert-scd.c
@@ -120,7 +120,7 @@ ask_for_card (ctrl_t ctrl, const unsigned char *shadow_info, char **r_kid)
else
{
rc = agent_get_confirmation (ctrl, desc, NULL, NULL);
- free (desc);
+ xfree (desc);
}
}
if (rc)
@@ -293,7 +293,7 @@ getpin_cb (void *opaque, const char *info, char *buf, size_t maxbuf)
info? "')":"") < 0)
desc = NULL;
rc = agent_askpin (ctrl, desc?desc:info, prompt, NULL, pi);
- free (desc);
+ xfree (desc);
}
if (!rc)
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index 5ac951c23..dc13c9908 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -263,6 +263,13 @@ static int fixed_gcry_pth_init (void)
}
+#ifndef PTH_HAVE_PTH_THREAD_ID
+static unsigned long pth_thread_id (void)
+{
+ return (unsigned long)pth_self ();
+}
+#endif
+
/*
@@ -840,6 +847,7 @@ main (int argc, char **argv )
|JNLIB_LOG_WITH_TIME
|JNLIB_LOG_WITH_PID));
current_logfile = xstrdup (logfile);
+ assuan_set_assuan_log_stream (log_get_stream ());
}
/* Make sure that we have a default ttyname. */
@@ -1034,11 +1042,11 @@ main (int argc, char **argv )
printf ("%s; export SSH_AGENT_PID;\n", infostr_ssh_pid);
}
}
- free (infostr); /* (Note that a vanilla free is here correct.) */
+ xfree (infostr);
if (opt.ssh_support)
{
- free (infostr_ssh_sock);
- free (infostr_ssh_pid);
+ xfree (infostr_ssh_sock);
+ xfree (infostr_ssh_pid);
}
exit (0);
}
@@ -1132,31 +1140,33 @@ agent_init_default_ctrl (ctrl_t ctrl)
and the request will fail anyway shortly after this
initialization. */
if (ctrl->display)
- free (ctrl->display);
- ctrl->display = default_display? strdup (default_display) : NULL;
+ xfree (ctrl->display);
+ ctrl->display = default_display? xtrystrdup (default_display) : NULL;
if (ctrl->ttyname)
- free (ctrl->ttyname);
- ctrl->ttyname = default_ttyname? strdup (default_ttyname) : NULL;
+ xfree (ctrl->ttyname);
+ ctrl->ttyname = default_ttyname? xtrystrdup (default_ttyname) : NULL;
if (ctrl->ttytype)
- free (ctrl->ttytype);
- ctrl->ttytype = default_ttytype? strdup (default_ttytype) : NULL;
+ xfree (ctrl->ttytype);
+ ctrl->ttytype = default_ttytype? xtrystrdup (default_ttytype) : NULL;
if (ctrl->lc_ctype)
- free (ctrl->lc_ctype);
- ctrl->lc_ctype = default_lc_ctype? strdup (default_lc_ctype) : NULL;
+ xfree (ctrl->lc_ctype);
+ ctrl->lc_ctype = default_lc_ctype? xtrystrdup (default_lc_ctype) : NULL;
if (ctrl->lc_messages)
- free (ctrl->lc_messages);
- ctrl->lc_messages = default_lc_messages? strdup (default_lc_messages) : NULL;
+ xfree (ctrl->lc_messages);
+ ctrl->lc_messages = default_lc_messages? xtrystrdup (default_lc_messages)
+ /**/ : NULL;
if (ctrl->xauthority)
- free (ctrl->xauthority);
- ctrl->xauthority = default_xauthority? strdup (default_xauthority) : NULL;
+ xfree (ctrl->xauthority);
+ ctrl->xauthority = default_xauthority? xtrystrdup (default_xauthority)
+ /**/: NULL;
if (ctrl->pinentry_user_data)
- free (ctrl->pinentry_user_data);
+ xfree (ctrl->pinentry_user_data);
ctrl->pinentry_user_data = NULL;
}
@@ -1165,19 +1175,19 @@ static void
agent_deinit_default_ctrl (ctrl_t ctrl)
{
if (ctrl->display)
- free (ctrl->display);
+ xfree (ctrl->display);
if (ctrl->ttyname)
- free (ctrl->ttyname);
+ xfree (ctrl->ttyname);
if (ctrl->ttytype)
- free (ctrl->ttytype);
+ xfree (ctrl->ttytype);
if (ctrl->lc_ctype)
- free (ctrl->lc_ctype);
+ xfree (ctrl->lc_ctype);
if (ctrl->lc_messages)
- free (ctrl->lc_messages);
+ xfree (ctrl->lc_messages);
if (ctrl->xauthority)
- free (ctrl->xauthority);
+ xfree (ctrl->xauthority);
if (ctrl->pinentry_user_data)
- free (ctrl->pinentry_user_data);
+ xfree (ctrl->pinentry_user_data);
}
/* Reread parts of the configuration. Note, that this function is
@@ -1622,12 +1632,12 @@ start_connection_thread (void *arg)
agent_init_default_ctrl (ctrl);
if (opt.verbose)
log_info (_("handler 0x%lx for fd %d started\n"),
- (long)pth_self (), FD2INT(ctrl->thread_startup.fd));
+ pth_thread_id (), FD2INT(ctrl->thread_startup.fd));
start_command_handler (ctrl, GNUPG_INVALID_FD, ctrl->thread_startup.fd);
if (opt.verbose)
log_info (_("handler 0x%lx for fd %d terminated\n"),
- (long)pth_self (), FD2INT(ctrl->thread_startup.fd));
+ pth_thread_id (), FD2INT(ctrl->thread_startup.fd));
agent_deinit_default_ctrl (ctrl);
xfree (ctrl);
@@ -1647,12 +1657,12 @@ start_connection_thread_ssh (void *arg)
agent_init_default_ctrl (ctrl);
if (opt.verbose)
log_info (_("ssh handler 0x%lx for fd %d started\n"),
- (long)pth_self (), FD2INT(ctrl->thread_startup.fd));
+ pth_thread_id (), FD2INT(ctrl->thread_startup.fd));
start_command_handler_ssh (ctrl, ctrl->thread_startup.fd);
if (opt.verbose)
log_info (_("ssh handler 0x%lx for fd %d terminated\n"),
- (long)pth_self (), FD2INT(ctrl->thread_startup.fd));
+ pth_thread_id (), FD2INT(ctrl->thread_startup.fd));
agent_deinit_default_ctrl (ctrl);
xfree (ctrl);
diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c
index dbb8025b1..42c7d6c95 100644
--- a/agent/preset-passphrase.c
+++ b/agent/preset-passphrase.c
@@ -205,7 +205,7 @@ preset_passphrase (const char *keygrip)
}
wipememory (line, strlen (line));
- free (line);
+ xfree (line);
}
@@ -222,7 +222,7 @@ forget_passphrase (const char *keygrip)
gpg_strerror (gpg_error_from_syserror ()));
return;
}
- free (line);
+ xfree (line);
}
diff --git a/agent/trustlist.c b/agent/trustlist.c
index a154da899..027dec03e 100644
--- a/agent/trustlist.c
+++ b/agent/trustlist.c
@@ -463,8 +463,9 @@ insert_colons (const char *string)
{
char *buffer, *p;
size_t n = strlen (string);
+ size_t nnew = n + (n+1)/2;
- p = buffer = xtrymalloc ( n + (n+2)/3 + 1 );
+ p = buffer = xtrymalloc ( nnew + 1 );
if (!buffer)
return NULL;
while (*string)
@@ -478,6 +479,7 @@ insert_colons (const char *string)
}
}
*p = 0;
+ assert (strlen (buffer) <= nnew);
return buffer;
}
@@ -526,7 +528,7 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
fprformatted = insert_colons (fpr);
if (!fprformatted)
return out_of_core ();
- if (asprintf (&desc,
+ desc = xtryasprintf (
/* TRANSLATORS: This prompt is shown by the Pinentry
and has one special property: A "%%0A" is used by
Pinentry to insert a line break. The double
@@ -539,7 +541,8 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
_("Please verify that the certificate identified as:%%0A"
" \"%s\"%%0A"
"has the fingerprint:%%0A"
- " %s"), name, fprformatted) < 0 )
+ " %s"), name, fprformatted);
+ if (!desc)
{
xfree (fprformatted);
return out_of_core ();
@@ -549,7 +552,7 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
be hit if the fingerprint matches the one of the CA. The other
button is "the default "Cancel" of the Pinentry. */
err = agent_get_confirmation (ctrl, desc, _("Correct"), NULL);
- free (desc);
+ xfree (desc);
/* If the user did not confirmed this, we return cancel here so that
gpgsm may stop asking further questions. We won't do this for
the second question of course. */
@@ -562,7 +565,7 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
- if (asprintf (&desc,
+ desc = xtryasprintf (
/* TRANSLATORS: This prompt is shown by the Pinentry
and has one special property: A "%%0A" is used by
Pinentry to insert a line break. The double
@@ -574,14 +577,15 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
_("Do you ultimately trust%%0A"
" \"%s\"%%0A"
"to correctly certify user certificates?"),
- name) < 0 )
+ name);
+ if (!desc)
{
xfree (fprformatted);
return out_of_core ();
}
err = agent_get_confirmation (ctrl, desc, _("Yes"), _("No"));
- free (desc);
+ xfree (desc);
if (err)
{
xfree (fprformatted);
diff --git a/agent/w32main.c b/agent/w32main.c
index bcdf340d5..9fc3abbef 100644
--- a/agent/w32main.c
+++ b/agent/w32main.c
@@ -92,10 +92,10 @@ build_argv (char *cmdline_arg, int reserved)
}
}
- argv = malloc (argc * sizeof *argv);
+ argv = xtrymalloc (argc * sizeof *argv);
if (!argv)
{
- free (cmdline);
+ xfree (cmdline);
return NULL;
}