Skip to content

Commit 7d04e0f

Browse files
committed
fix potential overflow in _php_stream_scandir
1 parent baacc2c commit 7d04e0f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ PHP NEWS
1010

1111
- Core:
1212
. Fixed CVE-2012-2143. (Solar Designer)
13+
. Fixed potential overflow in _php_stream_scandir. (Jason Powell,
14+
Stas)
1315

1416
- Fileinfo:
1517
. Fixed magic file regex support. (Felipe)

main/streams/streams.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,8 +2262,8 @@ PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_
22622262
php_stream *stream;
22632263
php_stream_dirent sdp;
22642264
char **vector = NULL;
2265-
int vector_size = 0;
2266-
int nfiles = 0;
2265+
unsigned int vector_size = 0;
2266+
unsigned int nfiles = 0;
22672267

22682268
if (!namelist) {
22692269
return FAILURE;
@@ -2281,12 +2281,17 @@ PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_
22812281
} else {
22822282
vector_size *= 2;
22832283
}
2284-
vector = (char **) erealloc(vector, vector_size * sizeof(char *));
2284+
vector = (char **) safe_erealloc(vector, vector_size, sizeof(char *), 0);
22852285
}
22862286

22872287
vector[nfiles] = estrdup(sdp.d_name);
22882288

22892289
nfiles++;
2290+
if(vector_size < 10 || nfiles == 0) {
2291+
/* overflow */
2292+
efree(vector);
2293+
return FAILURE;
2294+
}
22902295
}
22912296
php_stream_closedir(stream);
22922297

0 commit comments

Comments
 (0)