From b115781317b6a8c649ae2b92c7839ce8872fdffb Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 16 Oct 2024 19:27:36 +0900
Subject: [PATCH] journalctl: erase verify key before free

Even optarg is erased, copied string was not erased.
Let's erase the copied key for safety.

(cherry picked from commit d0ad4e88d4e6b5e312c359a6505125f7e088f3e3)
(cherry picked from commit 28f7c958fb799887cb67528a85ca59f0ccd9261e)
(cherry picked from commit 6b13398c220a01e2eff5bb25da7d457f445c82e9)

Conflict:the current code does not use STATIC_DESTRUCTOR_REGISTER instead of free, so the related code is not combined
Reference:https://github.com/systemd/systemd/commit/d0ad4e88d4e6b5e312c359a6505125f7e088f3e3
---
 src/journal/journalctl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index decdf14..327e035 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -791,9 +791,11 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_VERIFY_KEY:
-                        r = free_and_strdup(&arg_verify_key, optarg);
-                        if (r < 0)
-                                return r;
+                        erase_and_free(arg_verify_key);
+                        arg_verify_key = strdup(optarg);
+                        if (!arg_verify_key)
+                                return log_oom();
+
                         /* Use memset not explicit_bzero() or similar so this doesn't look confusing
                          * in ps or htop output. */
                         memset(optarg, 'x', strlen(optarg));
-- 
2.33.0

