Skip to content

Commit a35462c

Browse files
committed
Fixed bug that may dereferenced NULL pointer before checking
1 parent f9ca0ca commit a35462c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ext/standard/basic_functions.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,15 +4282,15 @@ PHP_FUNCTION(getopt)
42824282
/* the first <len> slots are filled by the one short ops
42834283
* we now extend our array and jump to the new added structs */
42844284
opts = (opt_struct *) erealloc(opts, sizeof(opt_struct) * (len + count + 1));
4285+
if (!opts) {
4286+
RETURN_FALSE;
4287+
}
4288+
42854289
orig_opts = opts;
42864290
opts += len;
42874291

42884292
memset(opts, 0, count * sizeof(opt_struct));
42894293

4290-
if (!opts) {
4291-
RETURN_FALSE;
4292-
}
4293-
42944294
/* Reset the array indexes. */
42954295
zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts));
42964296

@@ -4327,6 +4327,10 @@ PHP_FUNCTION(getopt)
43274327
}
43284328
} else {
43294329
opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1));
4330+
if (!opts) {
4331+
RETURN_FALSE;
4332+
}
4333+
43304334
orig_opts = opts;
43314335
opts += len;
43324336
}

0 commit comments

Comments
 (0)