]> granicus.if.org Git - php/commitdiff
Fixed bug that may dereferenced NULL pointer before checking
authorXinchen Hui <laruence@php.net>
Sun, 7 Aug 2011 13:19:04 +0000 (13:19 +0000)
committerXinchen Hui <laruence@php.net>
Sun, 7 Aug 2011 13:19:04 +0000 (13:19 +0000)
ext/standard/basic_functions.c

index d1cd20e86e04216de77fdd712040ea6b72bdc11a..aee53af2d90464dae1c52e8115ff50bdff41d1f8 100644 (file)
@@ -4313,15 +4313,15 @@ PHP_FUNCTION(getopt)
                /* the first <len> 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));
 
@@ -4358,6 +4358,10 @@ PHP_FUNCTION(getopt)
                }
        } else {
                opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1));
+               if (!opts) {
+                       RETURN_FALSE;
+               }
+
                orig_opts = opts;
                opts += len;
        }