Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_constants.c

From: Date: Thu, 01 Jul 2004 16:29:59 +0000
Subject: Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_constants.c
References: 1  Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-2718@lists.php.net to get a copy of this message
Why can this be easily abused? At 04:28 PM 7/1/2004 +0000, Ilia Alshanetsky wrote:
iliaa           Thu Jul  1 12:28:32 2004 EDT
Modified files:
    /ZendEngine2        zend_constants.c
Log: Do not use alloca() where it can be easily abused by the users. # This probably should go into reflection code as well. http://cvs.php.net/diff.php/ZendEngine2/zend_constants.c?r1=1.67&r2=1.68&ty=u Index: ZendEngine2/zend_constants.c diff -u ZendEngine2/zend_constants.c:1.67 ZendEngine2/zend_constants.c:1.68 --- ZendEngine2/zend_constants.c:1.67 Wed May 26 17:01:37 2004
+++ ZendEngine2/zend_constants.c        Thu Jul  1 12:28:32 2004
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: zend_constants.c,v 1.67 2004/05/26 21:01:37 andrei Exp $ */ +/* $Id: zend_constants.c,v 1.68 2004/07/01 16:28:32 iliaa Exp $ */ #include "zend.h" #include "zend_constants.h" @@ -231,10 +231,8 @@
                        scope = CG(active_class_entry);
                }
-               class_name = do_alloca(class_name_len+1);
-               memcpy(class_name, name, class_name_len);
-               class_name[class_name_len] = '\0';
-
+               class_name = estrndup(name, class_name_len);
+
                if (class_name_len == sizeof("self")-1 && strcmp(class_name, "self") == 0) {
                        if (scope) {
                                ce = &scope;
@@ -255,7 +253,7 @@
                                retval = 0;
                        }
                }
-               free_alloca(class_name);
+               efree(class_name);
                if (retval && ce) {
                        if (zend_hash_find(&((*ce)->constants_table), constant_name, const_name_len+1, (void **) &ret_constant) != SUCCESS) {
@@ -275,9 +273,8 @@
        }
        if (zend_hash_find(EG(zend_constants), name, name_len+1, (void **) &c) == FAILURE) {
-               lookup_name = do_alloca(name_len+1);
-               zend_str_tolower_copy(lookup_name, name, name_len);
-               lookup_name[name_len] = '\0';
+               lookup_name = estrndup(name, name_len);
+               zend_str_tolower(lookup_name, name_len);
                if (zend_hash_find(EG(zend_constants), lookup_name, name_len+1, (void **) &c)==SUCCESS) {
                        if ((c->flags & CONST_CS) && memcmp(c->name, name, name_len)!=0) {
@@ -286,7 +283,7 @@
                } else {
                        retval=0;
                }
-               free_alloca(lookup_name);
+               efree(lookup_name);
        }
        if (retval) {
@@ -312,8 +309,8 @@
        if (!(c->flags & CONST_CS)) {
                /* keep in mind that c->name_len already contains the '\0' */
-               lowercase_name = do_alloca(c->name_len);
-               zend_str_tolower_copy(lowercase_name, c->name, c->name_len - 1);
+               lowercase_name = estrndup(c->name, c->name_len);
+               zend_str_tolower(lowercase_name, c->name_len);
                name = lowercase_name;
        } else {
                name = c->name;
@@ -328,7 +325,7 @@
                ret = FAILURE;
        }
        if (lowercase_name) {
-               free_alloca(lowercase_name);
+               efree(lowercase_name);
        }
        return ret;
} -- Zend Engine CVS Mailing List (http://cvs.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.zend-engine.cvs (#2718) next »