From 01de3ea1e284df9d51df98c445db6ffa44a89215 Mon Sep 17 00:00:00 2001 From: Misaki Kasumi Date: Sat, 21 Dec 2024 02:46:00 +0800 Subject: [PATCH] nsenter: Fix argument parsing --- src/ostree/ot-admin-builtin-nsenter.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ostree/ot-admin-builtin-nsenter.c b/src/ostree/ot-admin-builtin-nsenter.c index bf6a14772a..a6859d679a 100644 --- a/src/ostree/ot-admin-builtin-nsenter.c +++ b/src/ostree/ot-admin-builtin-nsenter.c @@ -49,14 +49,14 @@ ot_admin_builtin_nsenter (int argc, char **argv, OstreeCommandInvocation *invoca context = g_option_context_new ("[PROGRAM [ARGUMENTS...]]"); - int new_argc = argc; - char **new_argv = argv; + int new_argc = 0; + char **new_argv = NULL; for (int i = 1; i < argc; i++) { if (g_str_equal (argv[i], "--")) { - new_argc -= i; + new_argc = argc - i; argc = i; new_argv = argv + i; argv[i] = NULL; @@ -69,8 +69,11 @@ ot_admin_builtin_nsenter (int argc, char **argv, OstreeCommandInvocation *invoca invocation, &sysroot, cancellable, error)) return FALSE; - argc = new_argc; - argv = new_argv; + if (new_argv) + { + argc = new_argc; + argv = new_argv; + } if (argc <= 1) { arguments = g_malloc_n (2, sizeof (char *));