Skip to content

Conversation

@hzeller
Copy link
Contributor

@hzeller hzeller commented Nov 21, 2022

Found with msan analysis.

Found with msan/asan analysis.

Signed-off-by: Henner Zeller <[email protected]>
@hzeller hzeller force-pushed the 20221121-fix-invalid-null-access branch from c30e56e to c39a501 Compare November 21, 2022 20:52
@tkoeppe
Copy link

tkoeppe commented Nov 21, 2022

With UBSAN, actually! It's UB to a) shift signed ints too much, and b) do non-trivial arithmetic on null pointers

Comment on lines +99 to +111
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;
}
Copy link

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;
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants