summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-13 16:24:53 +0200
committerThomas Haller <thaller@redhat.com>2020-07-13 17:15:56 +0200
commit09c94bc24f30a4a8ca57638fe6dc845d816db812 (patch)
treed8faf0d6484b9f7aed923918d710b781e1edb972
parent16abfca78a115568468a070749de73bf46f43c4d (diff)
downloadNetworkManager-09c94bc24f30a4a8ca57638fe6dc845d816db812.tar.gz
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
-rw-r--r--clients/cli/connections.c9
1 files 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: <setting>.<property> 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;