]> granicus.if.org Git - php/commitdiff
MFH: Fixed overflow crash (at least on Windows) in div_function with LONG_MIN / -1
authorMatt Wilmas <mattwil@php.net>
Thu, 29 May 2008 11:45:13 +0000 (11:45 +0000)
committerMatt Wilmas <mattwil@php.net>
Thu, 29 May 2008 11:45:13 +0000 (11:45 +0000)
Zend/zend_operators.c

index 6a905cef9d0ee65247a31fa05f2aa5a5925d6cdf..08ea3b0df8356b3e2650d41d01d0ab1194831ddc 100644 (file)
@@ -934,6 +934,10 @@ ZEND_API int div_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
                                        zend_error(E_WARNING, "Division by zero");
                                        ZVAL_BOOL(result, 0);
                                        return FAILURE;                 /* division by zero */
+                               } else if (Z_LVAL_P(op2) == -1 && Z_LVAL_P(op1) == LONG_MIN) {
+                                       /* Prevent overflow error/crash */
+                                       ZVAL_DOUBLE(result, (double) LONG_MIN / -1);
+                                       return SUCCESS;
                                }
                                if (Z_LVAL_P(op1) % Z_LVAL_P(op2) == 0) { /* integer */
                                        ZVAL_LONG(result, Z_LVAL_P(op1) / Z_LVAL_P(op2));