mirror of
https://git.proxmox.com/git/fwupd
synced 2025-06-09 10:20:28 +00:00
Fix segfault when parsing an invalid i2c device
Confusingly, g_regex_match_full() returns FALSE and doesn't always set the GError. Just use g_path_get_basename() and g_str_has_prefix().
This commit is contained in:
parent
7b96c2e6cd
commit
bb548f15f0
@ -114,8 +114,7 @@ fu_i2c_device_probe(FuDevice *device, GError **error)
|
|||||||
FuI2cDevicePrivate *priv = GET_PRIVATE(self);
|
FuI2cDevicePrivate *priv = GET_PRIVATE(self);
|
||||||
GUdevDevice *udev_device = fu_udev_device_get_dev(FU_UDEV_DEVICE(device));
|
GUdevDevice *udev_device = fu_udev_device_get_dev(FU_UDEV_DEVICE(device));
|
||||||
const gchar *tmp;
|
const gchar *tmp;
|
||||||
g_autoptr(GMatchInfo) info = NULL;
|
g_autofree gchar *devname = NULL;
|
||||||
g_autoptr(GRegex) regex = NULL;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* set physical ID */
|
/* set physical ID */
|
||||||
@ -130,13 +129,13 @@ fu_i2c_device_probe(FuDevice *device, GError **error)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* get bus number out of sysfs path */
|
/* get bus number out of sysfs path */
|
||||||
regex = g_regex_new("/i2c-([0-9]+)/", 0, 0, error);
|
devname = g_path_get_basename(fu_udev_device_get_sysfs_path(FU_UDEV_DEVICE(device)));
|
||||||
if (regex == NULL)
|
if (g_str_has_prefix(devname, "i2c-")) {
|
||||||
return FALSE;
|
guint64 tmp64 = 0;
|
||||||
tmp = g_udev_device_get_sysfs_path(udev_device);
|
if (!fu_strtoull(devname + 4, &tmp64, 0, G_MAXUINT, error))
|
||||||
if (!g_regex_match_full(regex, tmp, -1, 0, 0, &info, error))
|
return FALSE;
|
||||||
return FALSE;
|
priv->bus_number = tmp64;
|
||||||
priv->bus_number = g_ascii_strtoll(g_match_info_fetch(info, 1), NULL, 10);
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* success */
|
/* success */
|
||||||
|
Loading…
Reference in New Issue
Block a user