Skip to content

Commit d10b1ae

Browse files
committed
Handle errors during PRODUCT property parsing better
Instead of returning 0 for garbage, actually error out.
1 parent 1e961a2 commit d10b1ae

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

libwacom/libwacom.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ get_bus_vid_pid(GUdevDevice *device,
106106
g_auto(GStrv) splitted_product = NULL;
107107
unsigned int bus_id;
108108
gboolean retval = FALSE;
109+
guint64 val;
109110

110111
/* Parse that:
111112
* E: PRODUCT=5/56a/81/100
@@ -135,9 +136,18 @@ get_bus_vid_pid(GUdevDevice *device,
135136
goto out;
136137
}
137138

138-
bus_id = (int)strtoul(splitted_product[0], NULL, 16);
139-
*vendor_id = (int)strtol(splitted_product[1], NULL, 16);
140-
*product_id = (int)strtol(splitted_product[2], NULL, 16);
139+
if (!g_ascii_string_to_unsigned(splitted_product[0], 16, 0, 0xff, &val, NULL))
140+
goto out;
141+
142+
bus_id = val;
143+
if (!g_ascii_string_to_unsigned(splitted_product[1], 16, 0, 0xffff, &val, NULL))
144+
goto out;
145+
146+
*vendor_id = (int)val;
147+
if (!g_ascii_string_to_unsigned(splitted_product[2], 16, 0, 0xffff, &val, NULL))
148+
goto out;
149+
150+
*product_id = (int)val;
141151

142152
switch (bus_id) {
143153
case 0:

0 commit comments

Comments
 (0)