logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

cvs: ZendEngine2(PHP_5_0) / zend_execute.c /tests bug31098.phpt: msg#00028

Subject: cvs: ZendEngine2(PHP_5_0) / zend_execute.c /tests bug31098.phpt
dmitry          Wed Jan 12 04:17:46 2005 EDT

  Modified files:              (Branch: PHP_5_0)
    /ZendEngine2        zend_execute.c 
    /ZendEngine2/tests  bug31098.phpt 
  Log:
  Fixed bug #31098 (isset false positive)
  
  
http://cvs.php.net/diff.php/ZendEngine2/zend_execute.c?r1=1.652.2.13&r2=1.652.2.14&ty=u
Index: ZendEngine2/zend_execute.c
diff -u ZendEngine2/zend_execute.c:1.652.2.13 
ZendEngine2/zend_execute.c:1.652.2.14
--- ZendEngine2/zend_execute.c:1.652.2.13       Tue Jan 11 16:59:56 2005
+++ ZendEngine2/zend_execute.c  Wed Jan 12 04:17:42 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_execute.c,v 1.652.2.13 2005/01/11 21:59:56 moriyoshi Exp $ */
+/* $Id: zend_execute.c,v 1.652.2.14 2005/01/12 09:17:42 dmitry Exp $ */
 
 #define ZEND_INTENSIVE_DEBUGGING 0
 
@@ -967,7 +967,24 @@
 
                                offset = get_zval_ptr(op2, Ts, &EG(free_op2), 
BP_VAR_R);
 
-                               if (offset->type != IS_LONG) {
+                               if (Z_TYPE_P(offset) == IS_STRING) {
+                                       char *strval;
+                                       long  lval;
+
+                                       strval = Z_STRVAL_P(offset);
+                                       if (is_numeric_string(strval, 
Z_STRLEN_P(offset), &lval, NULL, 0) == IS_LONG) {
+                                         ZVAL_LONG(&tmp, lval);
+                                               offset = &tmp;
+                                       } else {
+                                               if (type != BP_VAR_IS && type 
!= BP_VAR_UNSET) {
+                                                       zend_error(E_NOTICE, 
"Trying to get string index from a string");
+                                               }
+                                               *retval = &EG(error_zval_ptr);;
+                                               SELECTIVE_PZVAL_LOCK(**retval, 
result);
+                                               FREE_OP(Ts, op2, EG(free_op2));
+                                               return;
+                                       }
+                               } else if (offset->type != IS_LONG) {
                                        tmp = *offset;
                                        zval_copy_ctor(&tmp);
                                        convert_to_long(&tmp);
@@ -4032,32 +4049,39 @@
                        } else {
                                result = 
Z_OBJ_HT_P(*container)->has_dimension(*container, offset, 
(opline->extended_value == ZEND_ISEMPTY) TSRMLS_CC);
                        }
-               } else if ((*container)->type == IS_STRING) { /* string offsets 
*/
-                       zval tmp_offset;
+               } else if ((*container)->type == IS_STRING && !prop_dim) { /* 
string offsets */
+                       zval tmp;
 
-                       if (!prop_dim) {
-                               if (Z_TYPE_P(offset) != IS_LONG) {
-                                       tmp_offset = *offset;
-                                       zval_copy_ctor(&tmp_offset);
-                                       convert_to_long(&tmp_offset);
-                                       offset = &tmp_offset;
-                               }
-                               switch (opline->extended_value) {
-                                       case ZEND_ISSET:
-                                               if (offset->value.lval >= 0 && 
offset->value.lval < Z_STRLEN_PP(container)) {
-                                                       result = 1;
-                                               }
-                                               break;
-                                       case ZEND_ISEMPTY:
-                                               if (offset->value.lval >= 0 && 
offset->value.lval < Z_STRLEN_PP(container) && 
Z_STRVAL_PP(container)[offset->value.lval] != '0') {
-                                                       result = 1;
-                                               }
-                                               break;
+                       if (Z_TYPE_P(offset) == IS_STRING) {
+                               char *strval;
+                               long  lval;
+
+                               strval = Z_STRVAL_P(offset);
+                               if (is_numeric_string(strval, 
Z_STRLEN_P(offset), &lval, NULL, 0) == IS_LONG) {
+                                       ZVAL_LONG(&tmp, lval);
+                                       offset = &tmp;
                                }
+                       } else if (offset->type != IS_LONG) {
+                               tmp = *offset;
+                               zval_copy_ctor(&tmp);
+                               convert_to_long(&tmp);
+                               offset = &tmp;
+                       }
+                       switch (opline->extended_value) {
+                               case ZEND_ISSET:
+                                       if (offset->value.lval >= 0 && 
offset->value.lval < Z_STRLEN_PP(container)) {
+                                               result = 1;
+                                       }
+                                       break;
+                               case ZEND_ISEMPTY:
+                                       if (offset->value.lval >= 0 && 
offset->value.lval < Z_STRLEN_PP(container) && 
Z_STRVAL_PP(container)[offset->value.lval] != '0') {
+                                               result = 1;
+                                       }
+                                       break;
                        }
                }
        }
-       
+
        EX_T(opline->result.u.var).tmp_var.type = IS_BOOL;
 
        switch (opline->extended_value) {
http://cvs.php.net/diff.php/ZendEngine2/tests/bug31098.phpt?r1=1.1.2.1&r2=1.1.2.2&ty=u
Index: ZendEngine2/tests/bug31098.phpt
diff -u ZendEngine2/tests/bug31098.phpt:1.1.2.1 
ZendEngine2/tests/bug31098.phpt:1.1.2.2
--- ZendEngine2/tests/bug31098.phpt:1.1.2.1     Tue Jan 11 16:59:57 2005
+++ ZendEngine2/tests/bug31098.phpt     Wed Jan 12 04:17:45 2005
@@ -14,12 +14,44 @@
 var_dump(isset($a{'b'}));
 $a = '0';
 var_dump(isset($a{'b'}));
+
+$simpleString = "Bogus String Text";
+echo isset($simpleString->wrong)?"bug\n":"ok\n";
+echo isset($simpleString["wrong"])?"bug\n":"ok\n";
+echo isset($simpleString[-1])?"bug\n":"ok\n";
+echo isset($simpleString[0])?"ok\n":"bug\n";
+echo isset($simpleString["0"])?"ok\n":"bug\n";
+echo isset($simpleString["16"])?"ok\n":"bug\n";
+echo isset($simpleString["17"])?"bug\n":"ok\n";
+echo isset($simpleString["wrong"][0])?"bug\n":"ok\n";
+echo $simpleString->wrong === null?"ok\n":"bug\n";
+echo $simpleString["wrong"] === null?"ok\n":"bug\n";
+echo $simpleString["0"] === "B"?"ok\n":"bug\n";
+$simpleString["wrong"] = "f";
+echo $simpleString["0"] === "B"?"ok\n":"bug\n";
 ?>
 --EXPECTF--
 bool(false)
 bool(false)
 bool(false)
 bool(false)
-bool(true)
-bool(true)
+bool(false)
+bool(false)
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+
+Notice: Trying to get property of non-object in %sbug31098.php on line %d
+ok
+
+Notice: Trying to get string index from a string in %sbug31098.php on line %d
+ok
+ok
 
+Notice: Trying to get string index from a string in %sbug31098.php on line %d
+ok

-- 
Zend Engine CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>