Skip to content

Commit c39a501

Browse files
committed
Fix undefined behavior: invalid access of NULL ptr.
Found with msan/asan analysis. Signed-off-by: Henner Zeller <[email protected]>
1 parent 70cb339 commit c39a501

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/base/main/libSupport.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ void open_libs() {
7474
}
7575

7676
// Extract directories and read libraries
77-
done = 0;
7877
p = init_p;
79-
while (!done) {
78+
for (;;) {
8079
char *endp = strchr (p,':');
81-
if (endp == NULL) done = 1; // last directory in the list
82-
else *endp = 0; // end of string
80+
if (endp != NULL) *endp = 0; // end of string
8381

8482
dirp = opendir(p);
8583
if (dirp == NULL) {
@@ -119,7 +117,11 @@ void open_libs() {
119117
}
120118
}
121119
closedir(dirp);
122-
p = endp+1;
120+
if (endp == NULL) {
121+
break; // last directory in the list
122+
} else {
123+
p = endp+1;
124+
}
123125
}
124126

125127
ABC_FREE(init_p);

src/map/if/ifMan.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,19 @@ If_Man_t * If_ManStart( If_Par_t * pPars )
9696
Abc_Print( 1, "K = %d. Memory (bytes): Truth = %4d. Cut = %4d. Obj = %4d. Set = %4d. CutMin = %s\n",
9797
p->pPars->nLutSize, 8 * p->nTruth6Words[p->pPars->nLutSize], p->nCutBytes, p->nObjBytes, p->nSetBytes, p->pPars->fCutMin? "yes":"no" );
9898
// room for temporary truth tables
99-
p->puTemp[0] = p->pPars->fTruth? ABC_ALLOC( unsigned, 8 * p->nTruth6Words[p->pPars->nLutSize] ) : NULL;
100-
p->puTemp[1] = p->puTemp[0] + p->nTruth6Words[p->pPars->nLutSize]*2;
101-
p->puTemp[2] = p->puTemp[1] + p->nTruth6Words[p->pPars->nLutSize]*2;
102-
p->puTemp[3] = p->puTemp[2] + p->nTruth6Words[p->pPars->nLutSize]*2;
103-
p->puTempW = p->pPars->fTruth? ABC_ALLOC( word, p->nTruth6Words[p->pPars->nLutSize] ) : NULL;
99+
if ( p->pPars->fTruth )
100+
{
101+
p->puTemp[0] = p->pPars->fTruth? ABC_ALLOC( unsigned, 8 * p->nTruth6Words[p->pPars->nLutSize] ) : NULL;
102+
p->puTemp[1] = p->puTemp[0] + p->nTruth6Words[p->pPars->nLutSize]*2;
103+
p->puTemp[2] = p->puTemp[1] + p->nTruth6Words[p->pPars->nLutSize]*2;
104+
p->puTemp[3] = p->puTemp[2] + p->nTruth6Words[p->pPars->nLutSize]*2;
105+
p->puTempW = p->pPars->fTruth? ABC_ALLOC( word, p->nTruth6Words[p->pPars->nLutSize] ) : NULL;
106+
}
107+
else
108+
{
109+
p->puTemp[0] = p->puTemp[1] = p->puTemp[2] = p->puTemp[3] = NULL;
110+
p->puTempW = NULL;
111+
}
104112
if ( pPars->fUseDsd )
105113
{
106114
for ( v = 6; v <= Abc_MaxInt(6,p->pPars->nLutSize); v++ )

src/misc/extra/extraUtilUtil.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ char * Extra_UtilFileSearch(char *file, char *path, char *mode)
280280

281281
save_path = path = Extra_UtilStrsav(path);
282282
quit = 0;
283-
do {
283+
for (;;) {
284284
cp = strchr(path, ':');
285285
if (cp != 0) {
286286
*cp = '\0';
@@ -304,8 +304,12 @@ char * Extra_UtilFileSearch(char *file, char *path, char *mode)
304304
return filename;
305305
}
306306
ABC_FREE(filename);
307-
path = ++cp;
308-
} while (! quit);
307+
if (quit) {
308+
break;
309+
} else {
310+
path = ++cp;
311+
}
312+
}
309313

310314
ABC_FREE(save_path);
311315
return 0;

0 commit comments

Comments
 (0)