diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-13 16:24:53 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-08-04 23:44:59 +0200 |
commit | 45ad1c1e85bf6cbee50568428db04bba162170bd (patch) | |
tree | 604e3ef825584d91830993b1f8e72ddca333fd15 | |
parent | 8e47a94d4ec81d7fa5805d6ccbba84fd78182b28 (diff) | |
download | NetworkManager-45ad1c1e85bf6cbee50568428db04bba162170bd.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
(cherry picked from commit 09c94bc24f30a4a8ca57638fe6dc845d816db812)
(cherry picked from commit fd9e7d6167bfb5d1e21836f95c26b097d596c017)
-rw-r--r-- | clients/cli/connections.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 0e4a95e68a..dcbbe30de3 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -4776,13 +4776,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; |