From 1875bc185e066148108108892e30020f8d1cc5ef Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 13 May 2026 14:33:17 +0900 Subject: [PATCH 2/2] agent: Fix cmd_put_secret for saving input line. * agent/command.c (cmd_put_secret): Copy the input to newly allocated memory, so that the inquiry won't break anything. (cmd_get_passphrase): Use xtrystrdup and care about an error. -- Signed-off-by: NIIBE Yutaka --- agent/command.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/agent/command.c b/agent/command.c index 950d32799..9cf502e93 100644 --- a/agent/command.c +++ b/agent/command.c @@ -1706,7 +1706,7 @@ do_one_keyinfo (ctrl_t ctrl, const unsigned char *grip, assuan_context_t ctx, } else if (strcmp (shadow_info_type, "tpm2-v1") == 0) { - serialno = xstrdup("TPM-Protected"); + serialno = xstrdup ("TPM-Protected"); idstr = NULL; } else @@ -2089,7 +2089,14 @@ cmd_get_passphrase (assuan_context_t ctx, char *line) if (ctrl->restricted || !strcmp (cacheid, "X")) cacheid = NULL; else - cacheid = xstrdup (cacheid); + { + cacheid = xtrystrdup (cacheid); + if (!cacheid) + { + rc = gpg_error_from_syserror (); + goto leave; + } + } if (!strcmp (errtext, "X")) errtext = NULL; if (!strcmp (prompt, "X")) @@ -3583,7 +3590,8 @@ cmd_put_secret (assuan_context_t ctx, char *line) unsigned char *value = NULL; size_t valuelen = 0; size_t n; - char *p, *key, *ttlstr; + char *p, *ttlstr; + char *key = NULL; unsigned char *valstr; int ttl; char *string = NULL; @@ -3628,6 +3636,12 @@ cmd_put_secret (assuan_context_t ctx, char *line) err = set_error (GPG_ERR_ASS_PARAMETER, "no key given"); goto leave; } + key = xtrystrdup (key); + if (!key) + { + err = gpg_error_from_syserror (); + goto leave; + } if (!ttlstr || !*ttlstr || !(n = parse_ttl (ttlstr, &ttl))) { err = set_error (GPG_ERR_ASS_PARAMETER, "no or invalid TTL given"); @@ -3673,6 +3687,7 @@ cmd_put_secret (assuan_context_t ctx, char *line) leave: + xfree (key); if (string) { wipememory (string, strlen (string)); -- 2.53.0