Skip to content

Commit

Permalink
Fix undefined behavior: invalid access of NULL ptr.
Browse files Browse the repository at this point in the history
Found with msan analysis.

Signed-off-by: Henner Zeller <[email protected]>
  • Loading branch information
hzeller committed Nov 21, 2022
1 parent 70cb339 commit c30e56e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
12 changes: 7 additions & 5 deletions src/base/main/libSupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ void open_libs() {
}

// Extract directories and read libraries
done = 0;
p = init_p;
while (!done) {
for (;;) {
char *endp = strchr (p,':');
if (endp == NULL) done = 1; // last directory in the list
else *endp = 0; // end of string
if (endp != NULL) *endp = 0; // end of string

dirp = opendir(p);
if (dirp == NULL) {
Expand Down Expand Up @@ -119,7 +117,11 @@ void open_libs() {
}
}
closedir(dirp);
p = endp+1;
if (endp == NULL) {
break; // last directory in the list
} else {
p = endp+1;
}
}

ABC_FREE(init_p);
Expand Down
18 changes: 13 additions & 5 deletions src/map/if/ifMan.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,19 @@ If_Man_t * If_ManStart( If_Par_t * pPars )
Abc_Print( 1, "K = %d. Memory (bytes): Truth = %4d. Cut = %4d. Obj = %4d. Set = %4d. CutMin = %s\n",
p->pPars->nLutSize, 8 * p->nTruth6Words[p->pPars->nLutSize], p->nCutBytes, p->nObjBytes, p->nSetBytes, p->pPars->fCutMin? "yes":"no" );
// room for temporary truth tables
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;
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;
}
if ( pPars->fUseDsd )
{
for ( v = 6; v <= Abc_MaxInt(6,p->pPars->nLutSize); v++ )
Expand Down
10 changes: 7 additions & 3 deletions src/misc/extra/extraUtilUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ char * Extra_UtilFileSearch(char *file, char *path, char *mode)

save_path = path = Extra_UtilStrsav(path);
quit = 0;
do {
for (;;) {
cp = strchr(path, ':');
if (cp != 0) {
*cp = '\0';
Expand All @@ -304,8 +304,12 @@ char * Extra_UtilFileSearch(char *file, char *path, char *mode)
return filename;
}
ABC_FREE(filename);
path = ++cp;
} while (! quit);
if (quit) {
break;
} else {
path = ++cp;
}
}

ABC_FREE(save_path);
return 0;
Expand Down

0 comments on commit c30e56e

Please sign in to comment.