Debian Codegraph @

debian/patches/register-parse.patch

raw
1 commit eedf406a48e8354f680df19abb0784d9cd3ac1c5
2 Author: Yazen Ghannam <[email protected]>
3 Date: Mon Sep 17 11:57:04 2018 -0500
4
5 Fail to read/write if register number is not parsed correctly
6
7 It's possible that a user will provide a register number in a format
8 that strtoul() can't parse. strtoul() will return 0 if it fails to parse
9 a value. The msr-tools will then silently read/write to MSR 0x0 and
10 succeed. At best this may confuse the user, or at worst this will
11 unintentionally write bad data to the system.
12
13 Check that the register number parsing has succeeded. If it fails, then
14 inform the user, give a suggestion, and exit.
15
16 Signed-off-by: Yazen Ghannam <[email protected]>
17
18 --- a/rdmsr.c
19 +++ b/rdmsr.c
20 @@ -194,7 +194,11 @@ int main(int argc, char *argv[])
21 exit(127);
22 }
23
24 - reg = strtoul(argv[optind], NULL, 0);
25 + reg = strtoul(argv[optind], &endarg, 0);
26 + if (*endarg) {
27 + printf("Failed to parse register number.\n");
28 + exit(127);
29 + }
30
31 if (cpu == -1) {
32 doing_for_all = 1;
33 --- a/wrmsr.c
34 +++ b/wrmsr.c
35 @@ -121,7 +121,11 @@ int main(int argc, char *argv[])
36 exit(127);
37 }
38
39 - reg = strtoul(argv[optind++], NULL, 0);
40 + reg = strtoul(argv[optind++], &endarg, 0);
41 + if (*endarg) {
42 + printf("Failed to parse register number.\n");
43 + exit(127);
44 + }
45
46 if (cpu == -1) {
47 doing_for_all = 1;