fix dumping semaphores by name

There was no check for strtoul success or failure (it returns 0 on
failure but that is also a valid conversion result). Detect if endptr
has been advanced instead (meaning there were some parsed characters in
strtoul so the argument at least starts with a number)

Change-Id: Ieefbd57a250ddcdb9362094389151c2a432e4c73
Reviewed-on: https://review.haiku-os.org/c/1683
Reviewed-by: Rene Gollent <rene@gollent.com>
This commit is contained in:
Adrien Destugues 2019-08-05 18:59:48 +02:00 committed by Rene Gollent
parent 58d16d9fe2
commit 87bdc2b02b

View File

@ -231,20 +231,23 @@ dump_sem_info(int argc, char **argv)
return 0;
}
num = strtoul(argv[1], NULL, 0);
char* endptr;
num = strtoul(argv[1], &endptr, 0);
if (IS_KERNEL_ADDRESS(num)) {
dump_sem((struct sem_entry *)num);
return 0;
} else if (num >= 0) {
uint32 slot = num % sMaxSems;
if (sSems[slot].id != (int)num) {
kprintf("sem %ld (%#lx) doesn't exist!\n", num, num);
if (endptr != argv[1]) {
if (IS_KERNEL_ADDRESS(num)) {
dump_sem((struct sem_entry *)num);
return 0;
} else {
uint32 slot = num % sMaxSems;
if (sSems[slot].id != (int)num) {
kprintf("sem %ld (%#lx) doesn't exist!\n", num, num);
return 0;
}
dump_sem(&sSems[slot]);
return 0;
}
dump_sem(&sSems[slot]);
return 0;
}
// walk through the sem list, trying to match name