From: Xinchen Hui Date: Sun, 7 Aug 2011 13:19:04 +0000 (+0000) Subject: Fixed bug that may dereferenced NULL pointer before checking X-Git-Tag: php-5.4.0beta1~498 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59b7b2701c4dd8371459ecbf6962fa42ce804ee2;p=php Fixed bug that may dereferenced NULL pointer before checking --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index ba83eb38d8..cce6880338 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4252,15 +4252,15 @@ PHP_FUNCTION(getopt) /* the first slots are filled by the one short ops * we now extend our array and jump to the new added structs */ opts = (opt_struct *) erealloc(opts, sizeof(opt_struct) * (len + count + 1)); + if (!opts) { + RETURN_FALSE; + } + orig_opts = opts; opts += len; memset(opts, 0, count * sizeof(opt_struct)); - if (!opts) { - RETURN_FALSE; - } - /* Reset the array indexes. */ zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts)); @@ -4297,6 +4297,10 @@ PHP_FUNCTION(getopt) } } else { opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1)); + if (!opts) { + RETURN_FALSE; + } + orig_opts = opts; opts += len; }