]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: drop trailing NUls before parsing the nulstr 26958/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Mar 2023 02:59:44 +0000 (11:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 24 Mar 2023 06:21:59 +0000 (15:21 +0900)
No functional changes, just refactoring.

src/basic/process-util.c

index 2fc2f924509ed4dc25161ab4d4724cb7bea957c9..cf2dca1dc481057ea4b1a1f09ce3d954b8f1c93d 100644 (file)
@@ -222,18 +222,12 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
 
                 _cleanup_strv_free_ char **args = NULL;
 
-                args = strv_parse_nulstr(t, k);
+                /* Drop trailing NULs, otherwise strv_parse_nulstr() adds additional empty strings at the end.
+                 * See also issue #21186. */
+                args = strv_parse_nulstr_full(t, k, /* drop_trailing_nuls = */ true);
                 if (!args)
                         return -ENOMEM;
 
-                /* Drop trailing empty strings. See issue #21186. */
-                STRV_FOREACH_BACKWARDS(p, args) {
-                        if (!isempty(*p))
-                                break;
-
-                        *p = mfree(*p);
-                }
-
                 ans = quote_command_line(args, shflags);
                 if (!ans)
                         return -ENOMEM;