-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix undefined behavior: invalid access of NULL ptr. #197
base: master
Are you sure you want to change the base?
Fix undefined behavior: invalid access of NULL ptr. #197
Conversation
Found with msan/asan analysis. Signed-off-by: Henner Zeller <[email protected]>
c30e56e
to
c39a501
Compare
With UBSAN, actually! It's UB to a) shift signed ints too much, and b) do non-trivial arithmetic on null pointers |
if ( p->pPars->fTruth ) | ||
{ | ||
p->puTemp[0] = p->pPars->fTruth? ABC_ALLOC( unsigned, 8 * p->nTruth6Words[p->pPars->nLutSize] ) : NULL; | ||
p->puTemp[1] = p->puTemp[0] + p->nTruth6Words[p->pPars->nLutSize]*2; | ||
p->puTemp[2] = p->puTemp[1] + p->nTruth6Words[p->pPars->nLutSize]*2; | ||
p->puTemp[3] = p->puTemp[2] + p->nTruth6Words[p->pPars->nLutSize]*2; | ||
p->puTempW = p->pPars->fTruth? ABC_ALLOC( word, p->nTruth6Words[p->pPars->nLutSize] ) : NULL; | ||
} | ||
else | ||
{ | ||
p->puTemp[0] = p->puTemp[1] = p->puTemp[2] = p->puTemp[3] = NULL; | ||
p->puTempW = NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would welcome a somewhat careful review of this change. It wasn't immediately clear to me if in the case of !p->pPars->fTruth
the various p->pu*
pointers are actually unused. This case currently has undefined behaviour, but maybe there's some obscure pointer-to-offset logic somewhere else that actually needed those "null pointer increments"?
if (quit) { | ||
break; | ||
} else { | ||
path = ++cp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same mistake fixed twice in this patch: the increment must not happen after the last round of the loop.
Found with msan analysis.