summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-02-04 15:47:03 +0100
committerThomas Haller <thaller@redhat.com>2019-02-05 08:45:38 +0100
commit2c80175e33f5bc6044143b2158563c610ffd2c79 (patch)
tree3ab0178c348e510e0c6bbdecc192faa89a1a0367
parent548b238039d72ff630df75e50246537f7b18491b (diff)
downloadNetworkManager-th/wifi-p2p-various.tar.gz
wifi-p2p: strict validate options argument to "StartFind"th/wifi-p2p-various
Don't accept any unsupported options.
-rw-r--r--libnm-core/nm-errors.h2
-rw-r--r--src/devices/wifi/nm-device-wifi-p2p.c44
-rw-r--r--src/supplicant/nm-supplicant-interface.c1
3 files changed, 34 insertions, 13 deletions
diff --git a/libnm-core/nm-errors.h b/libnm-core/nm-errors.h
index bdd6c2234f..ef73790e6b 100644
--- a/libnm-core/nm-errors.h
+++ b/libnm-core/nm-errors.h
@@ -145,6 +145,7 @@ GQuark nm_crypto_error_quark (void);
* @NM_DEVICE_ERROR_VERSION_ID_MISMATCH: the version id did not match.
* @NM_DEVICE_ERROR_MISSING_DEPENDENCIES: the requested operation could not
* be completed due to missing dependencies.
+ * @NM_DEVICE_ERROR_INVALID_ARGUMENT: invalid argument. Since: 1.16
*
* Device-related errors.
*
@@ -163,6 +164,7 @@ typedef enum {
NM_DEVICE_ERROR_SPECIFIC_OBJECT_NOT_FOUND, /*< nick=SpecificObjectNotFound >*/
NM_DEVICE_ERROR_VERSION_ID_MISMATCH, /*< nick=VersionIdMismatch >*/
NM_DEVICE_ERROR_MISSING_DEPENDENCIES, /*< nick=MissingDependencies >*/
+ NM_DEVICE_ERROR_INVALID_ARGUMENT, /*< nick=InvalidArgument >*/
} NMDeviceError;
#define NM_DEVICE_ERROR nm_device_error_quark ()
diff --git a/src/devices/wifi/nm-device-wifi-p2p.c b/src/devices/wifi/nm-device-wifi-p2p.c
index 508ff65f51..2c56a9a7cc 100644
--- a/src/devices/wifi/nm-device-wifi-p2p.c
+++ b/src/devices/wifi/nm-device-wifi-p2p.c
@@ -1006,22 +1006,43 @@ impl_device_wifi_p2p_start_find (NMDBusObject *obj,
NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P (obj);
NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self);
gs_unref_variant GVariant *options = NULL;
- gint32 timeout;
+ const char *opts_key;
+ GVariant *opts_val;
+ GVariantIter iter;
+ gint32 timeout = 30;
g_variant_get (parameters, "(@a{sv})", &options);
- if (!g_variant_lookup (options, "timeout", "i", &timeout)) {
- /* Default to running a find for 30s. */
- timeout = 30;
- }
+ g_variant_iter_init (&iter, options);
+ while (g_variant_iter_next (&iter, "{&sv}", &opts_key, &opts_val)) {
+ _nm_unused gs_unref_variant GVariant *opts_val_free = opts_val;
+
+ if (nm_streq (opts_key, "timeout")) {
+ if (!g_variant_is_of_type (opts_val, G_VARIANT_TYPE_INT32)) {
+ g_dbus_method_invocation_return_error_literal (invocation,
+ NM_DEVICE_ERROR,
+ NM_DEVICE_ERROR_INVALID_ARGUMENT,
+ "\"timeout\" must be an integer \"i\"");
+ return;
+ }
- /* Reject unreasonable timeout values. */
- if (timeout <= 0 || timeout > 600) {
- g_dbus_method_invocation_return_error_literal (invocation,
- NM_DEVICE_ERROR,
- NM_DEVICE_ERROR_NOT_ALLOWED,
- "The timeout for a find operation needs to be in the range of 1-600s.");
+ timeout = g_variant_get_int32 (opts_val);
+ if (timeout <= 0 || timeout > 600) {
+ g_dbus_method_invocation_return_error_literal (invocation,
+ NM_DEVICE_ERROR,
+ NM_DEVICE_ERROR_NOT_ALLOWED,
+ "The timeout for a find operation needs to be in the range of 1-600s.");
+ return;
+ }
+
+ continue;
+ }
+ g_dbus_method_invocation_return_error (invocation,
+ NM_DEVICE_ERROR,
+ NM_DEVICE_ERROR_INVALID_ARGUMENT,
+ "Unsupported options key \"%s\"",
+ opts_key);
return;
}
@@ -1030,7 +1051,6 @@ impl_device_wifi_p2p_start_find (NMDBusObject *obj,
NM_DEVICE_ERROR,
NM_DEVICE_ERROR_NOT_ACTIVE,
"WPA Supplicant management interface is currently unavailable.");
-
return;
}
diff --git a/src/supplicant/nm-supplicant-interface.c b/src/supplicant/nm-supplicant-interface.c
index 20fe5ef2c5..8a362e947f 100644
--- a/src/supplicant/nm-supplicant-interface.c
+++ b/src/supplicant/nm-supplicant-interface.c
@@ -2482,7 +2482,6 @@ nm_supplicant_interface_p2p_start_find (NMSupplicantInterface *self,
priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
- /* Find parameters */
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&builder, "{sv}", "Timeout", g_variant_new_int32 (timeout));