kernel-device: ID_USB_INTERFACE_NUM should be read as an hex string

The original g_udev_device_get_property_as_int() uses strtol() without
an explicit base (i.e. 0) so that the base is autodetected from the
string whenever possible (e.g. if prefixes with '0x' it is treated as a
hexadecimal string).

But, for ID_USB_INTERFACE_NUM, we explicitly require reading the number
as an hex string, even if we don't have any '0x' prefix.

Reported-by: Matthew Stanger <stangerm2@gmail.com>
This commit is contained in:
Aleksander Morgado
2016-11-07 19:36:26 +01:00
parent 4f748144b0
commit 820ab01ddf
6 changed files with 55 additions and 8 deletions

View File

@@ -579,6 +579,25 @@ kernel_device_get_property_as_int (MMKernelDevice *_self,
return g_udev_device_get_property_as_int (self->priv->device, property);
}
static guint
kernel_device_get_property_as_int_hex (MMKernelDevice *_self,
const gchar *property)
{
MMKernelDeviceUdev *self;
const gchar *s;
guint out = 0;
g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), -1);
self = MM_KERNEL_DEVICE_UDEV (_self);
if (!self->priv->device)
return -1;
s = g_udev_device_get_property (self->priv->device, property);
return ((s && mm_get_uint_from_hex_str (s, &out)) ? out : 0);
}
/*****************************************************************************/
MMKernelDevice *
@@ -767,6 +786,7 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass)
kernel_device_class->get_property = kernel_device_get_property;
kernel_device_class->get_property_as_boolean = kernel_device_get_property_as_boolean;
kernel_device_class->get_property_as_int = kernel_device_get_property_as_int;
kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex;
properties[PROP_UDEV_DEVICE] =
g_param_spec_object ("udev-device",