Skip to content

Commit 69c4f13

Browse files
committed
Fix: fail to read/write if register number is not parsed correctly
original commit : yghannam@eedf406
1 parent f6427fa commit 69c4f13

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

rdmsr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ int main(int argc, char *argv[])
194194
exit(127);
195195
}
196196

197-
reg = strtoul(argv[optind], NULL, 0);
197+
reg = strtoul(argv[optind], &endarg, 0);
198+
if (*endarg) {
199+
printf("Failed to parse register number. Do you need a prefix?\n");
200+
exit(127);
201+
}
198202

199203
if (cpu == -1) {
200204
doing_for_all = 1;

wrmsr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ int main(int argc, char *argv[])
121121
exit(127);
122122
}
123123

124-
reg = strtoul(argv[optind++], NULL, 0);
124+
reg = strtoul(argv[optind++], &endarg, 0);
125+
if (*endarg) {
126+
printf("Failed to parse register number. Do you need a prefix?\n");
127+
exit(127);
128+
}
125129

126130
if (cpu == -1) {
127131
doing_for_all = 1;

0 commit comments

Comments
 (0)