]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: fix possible NULL pointer dereference
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Feb 2025 15:42:18 +0000 (00:42 +0900)
committerLennart Poettering <lennart@poettering.net>
Tue, 18 Feb 2025 17:34:39 +0000 (18:34 +0100)
Fixes a bug introduced by 94a2b1cd25c93870a7a4ac904f6c0f2e4f902038.
Fixes CID#1591787.

src/basic/terminal-util.c

index 0a18577630381b93495b7290fdbdbd0dd0ddb8ae..fce3bb95a3cffce52ac661e74c422a4153218d70 100644 (file)
@@ -419,7 +419,10 @@ int ask_string_full(
                         /* Ctrl-u → erase all input */
 
                         clear_by_backspace(utf8_console_width(string));
-                        string[n = 0] = 0;
+                        if (string)
+                                string[n = 0] = 0;
+                        else
+                                assert(n == 0);
 
                 } else if (c == 4) {
                         /* Ctrl-d → cancel this field input */