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 c5d45848dd ('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: c5d45848dd ('cli: mark argv argument for command line parsing as const')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/492
This commit is contained in:
Thomas Haller 2020-07-13 16:24:53 +02:00
parent 16abfca78a
commit 09c94bc24f
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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;