Skip to content

Commit fc74503

Browse files
committed
improve overflow checks
1 parent 7d04e0f commit fc74503

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

main/streams/streams.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,11 @@ PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_
22792279
if (vector_size == 0) {
22802280
vector_size = 10;
22812281
} else {
2282+
if(vector_size*2 < vector_size) {
2283+
/* overflow */
2284+
efree(vector);
2285+
return FAILURE;
2286+
}
22822287
vector_size *= 2;
22832288
}
22842289
vector = (char **) safe_erealloc(vector, vector_size, sizeof(char *), 0);
@@ -2287,11 +2292,6 @@ PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_
22872292
vector[nfiles] = estrdup(sdp.d_name);
22882293

22892294
nfiles++;
2290-
if(vector_size < 10 || nfiles == 0) {
2291-
/* overflow */
2292-
efree(vector);
2293-
return FAILURE;
2294-
}
22952295
}
22962296
php_stream_closedir(stream);
22972297

0 commit comments

Comments
 (0)