1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-10 21:38:50 +01:00

(cmd_setattr): Use a copy of LINE.

(cmd_genkey): Use a copy of KEYNO.
(cmd_passwd): Use a copy of CHVNOSTR.
(cmd_pksign, cmd_pkauth, cmd_pkdecrypt): s/strdup/xtrystrdup/.
This commit is contained in:
Werner Koch 2003-08-25 09:58:02 +00:00
parent 4498a55dfb
commit ab0f32351d
2 changed files with 32 additions and 11 deletions

View File

@ -1,3 +1,10 @@
2003-08-25 Werner Koch <wk@gnupg.org>
* command.c (cmd_setattr): Use a copy of LINE.
(cmd_genkey): Use a copy of KEYNO.
(cmd_passwd): Use a copy of CHVNOSTR.
(cmd_pksign, cmd_pkauth, cmd_pkdecrypt): s/strdup/xtrystrdup/.
2003-08-19 Werner Koch <wk@gnupg.org> 2003-08-19 Werner Koch <wk@gnupg.org>
* scdaemon.c, scdaemon.h: New option --pcsc-driver. * scdaemon.c, scdaemon.h: New option --pcsc-driver.

View File

@ -577,7 +577,7 @@ cmd_pksign (ASSUAN_CONTEXT ctx, char *line)
/* We have to use a copy of the key ID because the function may use /* We have to use a copy of the key ID because the function may use
the pin_cb which in turn uses the assuan line buffer and thus the pin_cb which in turn uses the assuan line buffer and thus
overwriting the original line with the keyid */ overwriting the original line with the keyid */
keyidstr = strdup (line); keyidstr = xtrystrdup (line);
if (!keyidstr) if (!keyidstr)
return ASSUAN_Out_Of_Core; return ASSUAN_Out_Of_Core;
@ -593,7 +593,7 @@ cmd_pksign (ASSUAN_CONTEXT ctx, char *line)
pin_cb, ctx, pin_cb, ctx,
ctrl->in_data.value, ctrl->in_data.valuelen, ctrl->in_data.value, ctrl->in_data.valuelen,
&outdata, &outdatalen); &outdata, &outdatalen);
free (keyidstr); xfree (keyidstr);
if (rc) if (rc)
{ {
log_error ("card_sign failed: %s\n", gpg_strerror (rc)); log_error ("card_sign failed: %s\n", gpg_strerror (rc));
@ -630,7 +630,7 @@ cmd_pkauth (ASSUAN_CONTEXT ctx, char *line)
/* We have to use a copy of the key ID because the function may use /* We have to use a copy of the key ID because the function may use
the pin_cb which in turn uses the assuan line buffer and thus the pin_cb which in turn uses the assuan line buffer and thus
overwriting the original line with the keyid */ overwriting the original line with the keyid */
keyidstr = strdup (line); keyidstr = xtrystrdup (line);
if (!keyidstr) if (!keyidstr)
return ASSUAN_Out_Of_Core; return ASSUAN_Out_Of_Core;
@ -639,7 +639,7 @@ cmd_pkauth (ASSUAN_CONTEXT ctx, char *line)
pin_cb, ctx, pin_cb, ctx,
ctrl->in_data.value, ctrl->in_data.valuelen, ctrl->in_data.value, ctrl->in_data.valuelen,
&outdata, &outdatalen); &outdata, &outdatalen);
free (keyidstr); xfree (keyidstr);
if (rc) if (rc)
{ {
log_error ("app_auth_sign failed: %s\n", gpg_strerror (rc)); log_error ("app_auth_sign failed: %s\n", gpg_strerror (rc));
@ -670,7 +670,7 @@ cmd_pkdecrypt (ASSUAN_CONTEXT ctx, char *line)
if ((rc = open_card (ctrl))) if ((rc = open_card (ctrl)))
return rc; return rc;
keyidstr = strdup (line); keyidstr = xtrystrdup (line);
if (!keyidstr) if (!keyidstr)
return ASSUAN_Out_Of_Core; return ASSUAN_Out_Of_Core;
if (ctrl->app_ctx) if (ctrl->app_ctx)
@ -685,7 +685,7 @@ cmd_pkdecrypt (ASSUAN_CONTEXT ctx, char *line)
pin_cb, ctx, pin_cb, ctx,
ctrl->in_data.value, ctrl->in_data.valuelen, ctrl->in_data.value, ctrl->in_data.valuelen,
&outdata, &outdatalen); &outdata, &outdatalen);
free (keyidstr); xfree (keyidstr);
if (rc) if (rc)
{ {
log_error ("card_create_signature failed: %s\n", gpg_strerror (rc)); log_error ("card_create_signature failed: %s\n", gpg_strerror (rc));
@ -715,17 +715,24 @@ cmd_pkdecrypt (ASSUAN_CONTEXT ctx, char *line)
setattr function of the actually used application (app-*.c) for setattr function of the actually used application (app-*.c) for
details. */ details. */
static int static int
cmd_setattr (ASSUAN_CONTEXT ctx, char *line) cmd_setattr (ASSUAN_CONTEXT ctx, char *orig_line)
{ {
CTRL ctrl = assuan_get_pointer (ctx); CTRL ctrl = assuan_get_pointer (ctx);
int rc; int rc;
char *keyword; char *keyword;
int keywordlen; int keywordlen;
size_t nbytes; size_t nbytes;
char *line, *linebuf;
if ((rc = open_card (ctrl))) if ((rc = open_card (ctrl)))
return rc; return rc;
/* We need to use a copy of LINE, because PIN_CB uses the same
context and thus reuses the Assuan provided LINE. */
line = linebuf = xtrystrdup (orig_line);
if (!line)
return ASSUAN_Out_Of_Core;
keyword = line; keyword = line;
for (keywordlen=0; *line && !spacep (line); line++, keywordlen++) for (keywordlen=0; *line && !spacep (line); line++, keywordlen++)
; ;
@ -736,6 +743,7 @@ cmd_setattr (ASSUAN_CONTEXT ctx, char *line)
nbytes = percent_plus_unescape (line); nbytes = percent_plus_unescape (line);
rc = app_setattr (ctrl->app_ctx, keyword, pin_cb, ctx, line, nbytes); rc = app_setattr (ctrl->app_ctx, keyword, pin_cb, ctx, line, nbytes);
xfree (linebuf);
return map_to_assuan_status (rc); return map_to_assuan_status (rc);
} }
@ -788,8 +796,11 @@ cmd_genkey (ASSUAN_CONTEXT ctx, char *line)
if (!ctrl->app_ctx) if (!ctrl->app_ctx)
return gpg_error (GPG_ERR_UNSUPPORTED_OPERATION); return gpg_error (GPG_ERR_UNSUPPORTED_OPERATION);
keyno = xtrystrdup (keyno);
if (!keyno)
return ASSUAN_Out_Of_Core;
rc = app_genkey (ctrl->app_ctx, ctrl, keyno, force? 1:0, pin_cb, ctx); rc = app_genkey (ctrl->app_ctx, ctrl, keyno, force? 1:0, pin_cb, ctx);
xfree (keyno);
return map_to_assuan_status (rc); return map_to_assuan_status (rc);
} }
@ -866,10 +877,13 @@ cmd_passwd (ASSUAN_CONTEXT ctx, char *line)
if (!ctrl->app_ctx) if (!ctrl->app_ctx)
return gpg_error (GPG_ERR_UNSUPPORTED_OPERATION); return gpg_error (GPG_ERR_UNSUPPORTED_OPERATION);
rc = app_change_pin (ctrl->app_ctx, ctrl, chvnostr, reset_mode, pin_cb, ctx chvnostr = xtrystrdup (chvnostr);
); if (!chvnostr)
return ASSUAN_Out_Of_Core;
rc = app_change_pin (ctrl->app_ctx, ctrl, chvnostr, reset_mode, pin_cb, ctx);
if (rc) if (rc)
log_error ("command passwd failed: %s\n", gpg_strerror (rc)); log_error ("command passwd failed: %s\n", gpg_strerror (rc));
xfree (chvnostr);
return map_to_assuan_status (rc); return map_to_assuan_status (rc);
} }