scd: avoid memory leaks

* scd/app-p15.c (send_certinfo): free labelbuf
  (do_sign): goto leave instead of return
* scd/command.c (cmd_genkey): goto leave instead of return

--

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
GnuPG-bug-id: 5393

Modifified for this backport:

* scd/command.c (cmd_genkey): Make it easier to read by replacing
keyno with orig_line.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Jakub Jelen 2021-04-13 14:02:18 +02:00 committed by Werner Koch
parent 4dc4b025d6
commit 678e1b20d3
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 24 additions and 14 deletions

View File

@ -3851,6 +3851,7 @@ send_certinfo (app_t app, ctrl_t ctrl, const char *certtype,
labelbuf, strlen (labelbuf), labelbuf, strlen (labelbuf),
NULL, (size_t)0); NULL, (size_t)0);
xfree (buf); xfree (buf);
xfree (labelbuf);
} }
return 0; return 0;
} }
@ -5461,7 +5462,7 @@ do_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
if (err) if (err)
{ {
log_error ("p15: MSE failed: %s\n", gpg_strerror (err)); log_error ("p15: MSE failed: %s\n", gpg_strerror (err));
return err; goto leave;
} }
/* Now that we have all the information available run the actual PIN /* Now that we have all the information available run the actual PIN
@ -5500,7 +5501,7 @@ do_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
if (err) if (err)
{ {
log_error ("p15: MSE failed: %s\n", gpg_strerror (err)); log_error ("p15: MSE failed: %s\n", gpg_strerror (err));
return err; goto leave;
} }
if (prkdf->keyalgo == GCRY_PK_RSA && prkdf->keynbits > 2048) if (prkdf->keyalgo == GCRY_PK_RSA && prkdf->keynbits > 2048)

View File

@ -1113,7 +1113,7 @@ cmd_genkey (assuan_context_t ctx, char *line)
{ {
ctrl_t ctrl = assuan_get_pointer (ctx); ctrl_t ctrl = assuan_get_pointer (ctx);
int rc; int rc;
char *keyno; char *save_line;
int force; int force;
const char *s; const char *s;
time_t timestamp; time_t timestamp;
@ -1134,26 +1134,35 @@ cmd_genkey (assuan_context_t ctx, char *line)
line = skip_options (line); line = skip_options (line);
if (!*line) if (!*line)
return set_error (GPG_ERR_ASS_PARAMETER, "no key number given"); {
keyno = line; rc = set_error (GPG_ERR_ASS_PARAMETER, "no key number given");
goto leave;
}
save_line = line;
while (*line && !spacep (line)) while (*line && !spacep (line))
line++; line++;
*line = 0; *line = 0;
if ((rc = open_card (ctrl))) if ((rc = open_card (ctrl)))
return rc; goto leave;
if (!ctrl->app_ctx) if (!ctrl->app_ctx)
return gpg_error (GPG_ERR_UNSUPPORTED_OPERATION); {
rc = gpg_error (GPG_ERR_UNSUPPORTED_OPERATION);
goto leave;
}
keyno = xtrystrdup (keyno); {
if (!keyno) char *tmp = xtrystrdup (save_line);
return out_of_core (); if (!tmp)
rc = app_genkey (ctrl->app_ctx, ctrl, keyno, NULL, return gpg_error_from_syserror ();
force? APP_GENKEY_FLAG_FORCE : 0, rc = app_genkey (ctrl->app_ctx, ctrl, tmp, NULL,
timestamp, pin_cb, ctx); force? APP_GENKEY_FLAG_FORCE : 0,
xfree (keyno); timestamp, pin_cb, ctx);
xfree (tmp);
}
leave:
return rc; return rc;
} }