2008-08-30 Moritz <moritz@gnu.org>

* scdaemon.c (main): Use estream_asprintf instead of asprintf.
	* command.c (update_reader_status_file): Likewise.
	(cmd_serialno): Use estream_asprintf instead of asprintf
	and xfree instead of free to release memory allocated
	through (estream_)asprintf.
	(cmd_learn): Likewise.
	(pin_cb): Likewise.
	* app-openpgp.c (get_public_key): Likewise.
This commit is contained in:
Moritz Schulte 2008-08-31 11:55:09 +00:00
parent d92f06e882
commit 72110961f1
4 changed files with 32 additions and 21 deletions

View File

@ -1,3 +1,14 @@
2008-08-30 Moritz <moritz@gnu.org>
* scdaemon.c (main): Use estream_asprintf instead of asprintf.
* command.c (update_reader_status_file): Likewise.
(cmd_serialno): Use estream_asprintf instead of asprintf
and xfree instead of free to release memory allocated
through (estream_)asprintf.
(cmd_learn): Likewise.
(pin_cb): Likewise.
* app-openpgp.c (get_public_key): Likewise.
2008-08-18 Werner Koch <wk@g10code.com> 2008-08-18 Werner Koch <wk@g10code.com>
* app-openpgp.c (do_setattr): Fix test for v2 cards. * app-openpgp.c (do_setattr): Fix test for v2 cards.

View File

@ -1093,9 +1093,9 @@ get_public_key (app_t app, int keyno)
} }
hexkeyid = fpr + 24; hexkeyid = fpr + 24;
ret = asprintf (&command, ret = estream_asprintf (&command,
"gpg --list-keys --with-colons --with-key-data '%s'", "gpg --list-keys --with-colons --with-key-data '%s'",
fpr); fpr);
if (ret < 0) if (ret < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -1103,7 +1103,7 @@ get_public_key (app_t app, int keyno)
} }
fp = popen (command, "r"); fp = popen (command, "r");
free (command); xfree (command);
if (!fp) if (!fp)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();

View File

@ -471,13 +471,13 @@ cmd_serialno (assuan_context_t ctx, char *line)
if (rc) if (rc)
return rc; return rc;
rc = asprintf (&serial_and_stamp, "%s %lu", serial, (unsigned long)stamp); rc = estream_asprintf (&serial_and_stamp, "%s %lu", serial, (unsigned long)stamp);
xfree (serial); xfree (serial);
if (rc < 0) if (rc < 0)
return out_of_core (); return out_of_core ();
rc = 0; rc = 0;
assuan_write_status (ctx, "SERIALNO", serial_and_stamp); assuan_write_status (ctx, "SERIALNO", serial_and_stamp);
free (serial_and_stamp); xfree (serial_and_stamp);
return 0; return 0;
} }
@ -567,7 +567,7 @@ cmd_learn (assuan_context_t ctx, char *line)
rc = app_get_serial_and_stamp (ctrl->app_ctx, &serial, &stamp); rc = app_get_serial_and_stamp (ctrl->app_ctx, &serial, &stamp);
if (rc) if (rc)
return rc; return rc;
rc = asprintf (&serial_and_stamp, "%s %lu", serial, (unsigned long)stamp); rc = estream_asprintf (&serial_and_stamp, "%s %lu", serial, (unsigned long)stamp);
xfree (serial); xfree (serial);
if (rc < 0) if (rc < 0)
return out_of_core (); return out_of_core ();
@ -578,26 +578,26 @@ cmd_learn (assuan_context_t ctx, char *line)
{ {
char *command; char *command;
rc = asprintf (&command, "KNOWNCARDP %s", serial_and_stamp); rc = estream_asprintf (&command, "KNOWNCARDP %s", serial_and_stamp);
if (rc < 0) if (rc < 0)
{ {
free (serial_and_stamp); xfree (serial_and_stamp);
return out_of_core (); return out_of_core ();
} }
rc = 0; rc = 0;
rc = assuan_inquire (ctx, command, NULL, NULL, 0); rc = assuan_inquire (ctx, command, NULL, NULL, 0);
free (command); /* (must use standard free here) */ xfree (command);
if (rc) if (rc)
{ {
if (gpg_err_code (rc) != GPG_ERR_ASS_CANCELED) if (gpg_err_code (rc) != GPG_ERR_ASS_CANCELED)
log_error ("inquire KNOWNCARDP failed: %s\n", log_error ("inquire KNOWNCARDP failed: %s\n",
gpg_strerror (rc)); gpg_strerror (rc));
free (serial_and_stamp); xfree (serial_and_stamp);
return rc; return rc;
} }
/* not canceled, so we have to proceeed */ /* not canceled, so we have to proceeed */
} }
free (serial_and_stamp); xfree (serial_and_stamp);
} }
/* Let the application print out its collection of useful status /* Let the application print out its collection of useful status
@ -784,11 +784,11 @@ pin_cb (void *opaque, const char *info, char **retstr)
if (info) if (info)
{ {
log_debug ("prompting for keypad entry '%s'\n", info); log_debug ("prompting for keypad entry '%s'\n", info);
rc = asprintf (&command, "POPUPKEYPADPROMPT %s", info); rc = estream_asprintf (&command, "POPUPKEYPADPROMPT %s", info);
if (rc < 0) if (rc < 0)
return gpg_error (gpg_err_code_from_errno (errno)); return gpg_error (gpg_err_code_from_errno (errno));
rc = assuan_inquire (ctx, command, &value, &valuelen, MAXLEN_PIN); rc = assuan_inquire (ctx, command, &value, &valuelen, MAXLEN_PIN);
free (command); xfree (command);
} }
else else
{ {
@ -804,14 +804,14 @@ pin_cb (void *opaque, const char *info, char **retstr)
*retstr = NULL; *retstr = NULL;
log_debug ("asking for PIN '%s'\n", info); log_debug ("asking for PIN '%s'\n", info);
rc = asprintf (&command, "NEEDPIN %s", info); rc = estream_asprintf (&command, "NEEDPIN %s", info);
if (rc < 0) if (rc < 0)
return gpg_error (gpg_err_code_from_errno (errno)); return gpg_error (gpg_err_code_from_errno (errno));
/* Fixme: Write an inquire function which returns the result in /* Fixme: Write an inquire function which returns the result in
secure memory and check all further handling of the PIN. */ secure memory and check all further handling of the PIN. */
rc = assuan_inquire (ctx, command, &value, &valuelen, MAXLEN_PIN); rc = assuan_inquire (ctx, command, &value, &valuelen, MAXLEN_PIN);
free (command); xfree (command);
if (rc) if (rc)
return rc; return rc;
@ -1918,7 +1918,7 @@ update_reader_status_file (void)
gpg_error_t err; gpg_error_t err;
homestr = make_filename (opt.homedir, NULL); homestr = make_filename (opt.homedir, NULL);
if (asprintf (&envstr, "GNUPGHOME=%s", homestr) < 0) if (estream_asprintf (&envstr, "GNUPGHOME=%s", homestr) < 0)
log_error ("out of core while building environment\n"); log_error ("out of core while building environment\n");
else else
{ {
@ -1946,7 +1946,7 @@ update_reader_status_file (void)
log_error ("failed to run event handler `%s': %s\n", log_error ("failed to run event handler `%s': %s\n",
fname, gpg_strerror (err)); fname, gpg_strerror (err));
xfree (fname); xfree (fname);
free (envstr); xfree (envstr);
} }
xfree (homestr); xfree (homestr);
} }

View File

@ -702,8 +702,8 @@ main (int argc, char **argv )
close (fd); close (fd);
/* create the info string: <name>:<pid>:<protocol_version> */ /* create the info string: <name>:<pid>:<protocol_version> */
if (asprintf (&infostr, "SCDAEMON_INFO=%s:%lu:1", if (estream_asprintf (&infostr, "SCDAEMON_INFO=%s:%lu:1",
socket_name, (ulong)pid ) < 0) socket_name, (ulong) pid) < 0)
{ {
log_error ("out of core\n"); log_error ("out of core\n");
kill (pid, SIGTERM); kill (pid, SIGTERM);
@ -738,7 +738,7 @@ main (int argc, char **argv )
{ {
printf ( "%s; export SCDAEMON_INFO;\n", infostr); printf ( "%s; export SCDAEMON_INFO;\n", infostr);
} }
free (infostr); xfree (infostr);
exit (0); exit (0);
} }
/* NOTREACHED */ /* NOTREACHED */