Skip to content

Commit f25ab1b

Browse files
committed
- possible NULL deref
1 parent f45b9c4 commit f25ab1b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

win32/readdir.c

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ DIR *opendir(const char *dir)
3333
}
3434

3535
filespec = (char *)malloc(strlen(resolved_path_buff) + 2 + 1);
36+
if (filespec == NULL) {
37+
return NULL;
38+
}
3639
strcpy(filespec, resolved_path_buff);
3740
index = strlen(filespec) - 1;
3841
if (index >= 0 && (filespec[index] == '/' ||
@@ -41,6 +44,9 @@ DIR *opendir(const char *dir)
4144
strcat(filespec, "\\*");
4245

4346
dp = (DIR *) malloc(sizeof(DIR));
47+
if (dp == NULL) {
48+
return NULL;
49+
}
4450
dp->offset = 0;
4551
dp->finished = 0;
4652

@@ -140,6 +146,10 @@ int rewinddir(DIR *dp)
140146
dp->finished = 0;
141147

142148
filespec = (char *)malloc(strlen(dp->dir) + 2 + 1);
149+
if (filespec == NULL) {
150+
return -1;
151+
}
152+
143153
strcpy(filespec, dp->dir);
144154
index = strlen(filespec) - 1;
145155
if (index >= 0 && (filespec[index] == '/' ||

0 commit comments

Comments
 (0)