Skip to content

Commit d9eef34

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Check for string overflow from strscpy calls
The strscpy function is able to return an error code when a copy would overflow the size of the destination. The copy is stopped and the buffer terminated before overflow actually occurs so it is safe to continue execution, but we should still produce a warning should this occur. Signed-off-by: Jason Gerecke <[email protected]> Reviewed-by: Ping Cheng <[email protected]> Reviewed-by: Peter Hutterer <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 34da76d commit d9eef34

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/hid/wacom_sys.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,9 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix)
22242224
} else if (strstr(product_name, "Wacom") ||
22252225
strstr(product_name, "wacom") ||
22262226
strstr(product_name, "WACOM")) {
2227-
strscpy(name, product_name, sizeof(name));
2227+
if (strscpy(name, product_name, sizeof(name)) < 0) {
2228+
hid_warn(wacom->hdev, "String overflow while assembling device name");
2229+
}
22282230
} else {
22292231
snprintf(name, sizeof(name), "Wacom %s", product_name);
22302232
}
@@ -2242,7 +2244,9 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix)
22422244
if (name[strlen(name)-1] == ' ')
22432245
name[strlen(name)-1] = '\0';
22442246
} else {
2245-
strscpy(name, features->name, sizeof(name));
2247+
if (strscpy(name, features->name, sizeof(name)) < 0) {
2248+
hid_warn(wacom->hdev, "String overflow while assembling device name");
2249+
}
22462250
}
22472251

22482252
snprintf(wacom_wac->name, sizeof(wacom_wac->name), "%s%s",
@@ -2500,8 +2504,10 @@ static void wacom_wireless_work(struct work_struct *work)
25002504
goto fail;
25012505
}
25022506

2503-
strscpy(wacom_wac->name, wacom_wac1->name,
2504-
sizeof(wacom_wac->name));
2507+
if (strscpy(wacom_wac->name, wacom_wac1->name,
2508+
sizeof(wacom_wac->name)) < 0) {
2509+
hid_warn(wacom->hdev, "String overflow while assembling device name");
2510+
}
25052511
}
25062512

25072513
return;

0 commit comments

Comments
 (0)