From 59bd932af2c8f09c9cf509a405e217a749023033 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 28 Jan 2025 02:09:52 +0100 Subject: [PATCH 1/2] tty-ask-password-agent: assert that ask_on_consoles() is called without arg_device --- src/tty-ask-password-agent/tty-ask-password-agent.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 1c1b95bef3..26c135a45f 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -666,6 +666,7 @@ static int ask_on_consoles(char *argv[]) { _cleanup_set_free_ Set *pids = NULL; int r; + assert(!arg_device); assert(argv); r = get_kernel_consoles(&consoles); From ce8199a164559426c6be92cc84b18f850ee6d2c9 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 28 Jan 2025 02:07:16 +0100 Subject: [PATCH 2/2] tty-ask-password-agent: use free_and_strdup_warn() for arg_device Follow-up for 68cf1fc34d3e86a664fb948d413e1db4a24e16dd Fixes CID#1590840 --- src/tty-ask-password-agent/tty-ask-password-agent.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 26c135a45f..6950a8697e 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -495,7 +495,7 @@ static int parse_argv(int argc, char *argv[]) { {} }; - int c; + int r, c; assert(argc >= 0); assert(argv); @@ -537,9 +537,9 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Empty console device path is not allowed."); - arg_device = strdup(optarg); - if (!arg_device) - return log_oom(); + r = free_and_strdup_warn(&arg_device, optarg); + if (r < 0) + return r; } break;