Skip to content

Commit 3839583

Browse files
jigpuJoshua-Dickens
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]> [[email protected]: Imported into input-wacom repository (d9eef346b601)] Signed-off-by: Joshua Dickens <[email protected]>
1 parent 4546bff commit 3839583

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

4.5/wacom_sys.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,9 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix)
22842284
} else if (strstr(product_name, "Wacom") ||
22852285
strstr(product_name, "wacom") ||
22862286
strstr(product_name, "WACOM")) {
2287-
strscpy(name, product_name, sizeof(name));
2287+
if (strscpy(name, product_name, sizeof(name)) < 0) {
2288+
hid_warn(wacom->hdev, "String overflow while assembling device name");
2289+
}
22882290
} else {
22892291
snprintf(name, sizeof(name), "Wacom %s", product_name);
22902292
}
@@ -2302,7 +2304,9 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix)
23022304
if (name[strlen(name)-1] == ' ')
23032305
name[strlen(name)-1] = '\0';
23042306
} else {
2305-
strscpy(name, features->name, sizeof(name));
2307+
if (strscpy(name, features->name, sizeof(name)) < 0) {
2308+
hid_warn(wacom->hdev, "String overflow while assembling device name");
2309+
}
23062310
}
23072311

23082312
snprintf(wacom_wac->name, sizeof(wacom_wac->name), "%s%s",
@@ -2560,8 +2564,10 @@ static void wacom_wireless_work(struct work_struct *work)
25602564
goto fail;
25612565
}
25622566

2563-
strscpy(wacom_wac->name, wacom_wac1->name,
2564-
sizeof(wacom_wac->name));
2567+
if (strscpy(wacom_wac->name, wacom_wac1->name,
2568+
sizeof(wacom_wac->name)) < 0) {
2569+
hid_warn(wacom->hdev, "String overflow while assembling device name");
2570+
}
25652571
}
25662572

25672573
return;

0 commit comments

Comments
 (0)