From 521455df070273332c2846d685f01d50aa4374d4 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 28 May 2024 16:50:59 +0200 Subject: [PATCH] agent: Avoid uninitialized access in GENKEY command on parameter error. * agent/command.c (cmd_genkey): Moved init_membuf to the top. -- Signed-off-by: Jakub Jelen This is part of GnuPG-bug-id: 7129 (cherry picked from commit 379fc5569d604c4a7b5f12b2bbfc4106893c2a9e) --- agent/command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/command.c b/agent/command.c index 40322f385..f4bd1824f 100644 --- a/agent/command.c +++ b/agent/command.c @@ -1130,6 +1130,8 @@ cmd_genkey (assuan_context_t ctx, char *line) int c; unsigned int flags = 0; + init_membuf (&outbuf, 512); + if (ctrl->restricted) return leave_cmd (ctx, gpg_error (GPG_ERR_FORBIDDEN)); @@ -1187,8 +1189,6 @@ cmd_genkey (assuan_context_t ctx, char *line) if (rc) goto leave; - init_membuf (&outbuf, 512); - /* If requested, ask for the password to be used for the key. If this is not used the regular Pinentry mechanism is used. */ if (opt_inq_passwd && !(flags & GENKEY_FLAG_NO_PROTECTION))