wifi-p2p: strict validate options argument to "StartFind"

Don't accept any unsupported options.
This commit is contained in:
Thomas Haller 2019-02-04 15:47:03 +01:00
parent 1a7303a04c
commit 8076025780
3 changed files with 34 additions and 13 deletions

View file

@ -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 ()

View file

@ -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;
/* 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.");
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;
}
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;
}

View file

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