mirror of
https://github.com/netwide-assembler/nasm
synced 2026-08-26 16:23:04 -04:00
fix undefined behavior in count_mmac_params
When compiled -fsanitize=undefined nasm produced this error message:
asm/preproc.c:2523:25: runtime error: member access within null pointer of type 'struct Token'
The problem is reproducible on tests avx512f, avx512cd, avx512pf
and avx512er in the test suite.
The problematic line was:
/* Advance to the next comma */
maybe_comma = &t->next; <<< HERE
while (tok_isnt(t, ',')) {
if (!tok_white(t))
comma = NULL; /* Non-empty parameter */
maybe_comma = &t->next;
t = t->next;
}
When t is NULL this line doesn't cause memory access, but it is still an
undefined behavior according to C standard.
I believe that the underlying problem is that this loop doesn't have a sound
invariant about maybe_comma:
* On first iteration: *maybe_comma == t->next
* On the following iterations: *maybe_comma == t
I don't know what the intended loop invariant is and I decided to just
mechanically fix the deferencing of NULL pointer, completely preserving
the existing behavior.
Signed-off-by: Ivan Sorokin <vanyacpp@gmail.com>
This commit is contained in:
parent
ad297258c1
commit
bd7185bad1
1 changed files with 3 additions and 0 deletions
|
|
@ -2813,6 +2813,9 @@ static Token **count_mmac_params(Token *tline, int *nparamp, Token ***paramsp)
|
|||
}
|
||||
}
|
||||
|
||||
if (!t)
|
||||
break; /* End of string, no comma */
|
||||
|
||||
/* Advance to the next comma */
|
||||
maybe_comma = &t->next;
|
||||
while (tok_isnt(t, ',')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue