com php-src: Zend: fix overflow handling bug in non-x86 fast_add_function(): Zend/zend_operators.h

From: Date: Wed, 11 Dec 2013 07:50:20 +0000
Subject: com php-src: Zend: fix overflow handling bug in non-x86 fast_add_function(): Zend/zend_operators.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-74368@lists.php.net to get a copy of this message
Commit: 8f1fee61e2f0c24fd46d0ecbc6ded5c68bae7d6e Author: Ard Biesheuvel <ard.biesheuvel@linaro.org> Tue, 10 Dec 2013 12:07:46 +0100 Parents: b1b23abc868e25f9ee083e8837c37867516ee380 Branches: PHP-5.4 PHP-5.5 PHP-5.6 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8f1fee61e2f0c24fd46d0ecbc6ded5c68bae7d6e Log: Zend: fix overflow handling bug in non-x86 fast_add_function() The 'result' argument of fast_add_function() may alias with either of its operands (or both). Take care not to write to 'result' before reading op1 and op2. Changed paths: M Zend/zend_operators.h Diff: diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 700b578..815ef27 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -593,13 +593,18 @@ static zend_always_inline int fast_add_function(zval *result, zval *op1, zval *o "r"(op2) : "rax"); #else - Z_LVAL_P(result) = Z_LVAL_P(op1) + Z_LVAL_P(op2); + /* + * 'result' may alias with op1 or op2, so we need to + * ensure that 'result' is not updated until after we + * have read the values of op1 and op2. + */ if (UNEXPECTED((Z_LVAL_P(op1) & LONG_SIGN_MASK) == (Z_LVAL_P(op2) & LONG_SIGN_MASK) - && (Z_LVAL_P(op1) & LONG_SIGN_MASK) != (Z_LVAL_P(result) & LONG_SIGN_MASK))) { + && (Z_LVAL_P(op1) & LONG_SIGN_MASK) != ((Z_LVAL_P(op1) + Z_LVAL_P(op2)) & LONG_SIGN_MASK))) { Z_DVAL_P(result) = (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2); Z_TYPE_P(result) = IS_DOUBLE; } else { + Z_LVAL_P(result) = Z_LVAL_P(op1) + Z_LVAL_P(op2); Z_TYPE_P(result) = IS_LONG; } #endif

« previous php.cvs (#74368) next »