From 09c94bc24f30a4a8ca57638fe6dc845d816db812 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 13 Jul 2020 16:24:53 +0200 Subject: [PATCH] cli: fix accessing argv with zero elements in nmc_process_connection_properties() Without this, `nmcli device modify "$DEVICE"` leads to a crash. At least since commit c5d45848dd07 ('cli: mark argv argument for command line parsing as const'), when this happens. That is, because it passes a NULL strv array with argc being set to zero. nmc_process_connection_properties() is not supposed to access the array, if there are no elements there. Fixes: c5d45848dd07 ('cli: mark argv argument for command line parsing as const') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/492 --- clients/cli/connections.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 91f9b05a48..39f8be59f5 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -4709,13 +4709,18 @@ nmc_process_connection_properties (NmCli *nmc, ensure_settings (connection, slv_settings); ensure_settings (connection, type_settings); - option_orig = **argv; - if (!option_orig) { + if (*argc <= 0) { g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, _("Error: . argument is missing.")); return FALSE; } + nm_assert (argv); + nm_assert (*argv); + nm_assert (**argv); + + option_orig = **argv; + switch (option_orig[0]) { case '+': modifier = NM_META_ACCESSOR_MODIFIER_ADD; option = &option_orig[1]; break; case '-': modifier = NM_META_ACCESSOR_MODIFIER_DEL; option = &option_orig[1]; break;