Re: com php-src: Fix possible overflow in openssl_pbkdf2: ext/openssl/openssl.c
| From: | Matt Wilmas | Date: | Tue, 18 Aug 2015 22:16:05 +0000 |
| Subject: | Re: com php-src: Fix possible overflow in openssl_pbkdf2: ext/openssl/openssl.c | ||
| References: | 1 2 3 4 5 | Groups: | php.cvs php.internals |
| Request: | Send a blank email to internals+get-87782@lists.php.net to get a copy of this message | ||
Hi Anatol,
----- Original Message -----
From: "Anatol Belski"
Sent: Tuesday, August 18, 2015
Hi Matt, [...] The checks with zend_long vars like key_length and iterations are impossible when ZEND_LONG_MAX == INT_MAX (most if not all 32-bit, I guess). So those checks should already be removed by the compiler. It's unlikely to be optimized away, key_length is a variable, not a constant. It is "INT_MAX < variable", unlikely a compiler can predict what is in the variable, disregarding bitness.The compiler isn't stupid, and as Jakub says, knows the range (and signedness). This is a dead simple optimization that only a really bad compiler wouldn't do! With GCC, the function: void test(int foo) { if (foo > INT_MAX) printf("Overflow!\n"); } becomes ret # Just return instruction
But for the size_t ones, would need to check SIZEOF_SIZE_T > 4 around the macros or such. Or you could just change in the definition: Are there platforms where sizeof(size_t) <= sizeof(zend_long) ?All as far as I know (equal, not less; unless zend_long would be made 64-bit on 32-bit), although I didn't mention anything about that comparison...
By the current info, size_t is same as zend_ulong, so on any given platform sizeof(size_t) > sizeof(zend_long).No, on any platform sizeof(size_t) == sizeof(zend_long), never > unless the condition I just mentioned. But again, I didn't make this comparison...
And almost I were not aware of platforms SIZEOF_SIZE_T < 4 (some 16-bit?) but they should go by the same scheme, actually.I was only referring to check SIZEOF_SIZE_T > 4 (SIZEOF_SIZE_T == 8 is used in other areas) in an #if around the overflow checks of size_t vars (string length) with INT_MAX if not just changing the macro definition to allow removal. Overflow checks of zend_long with INT_MAX will automatically be removed when appropriate, as established; as will checks of size_t with UINT_MAX.
Regards Anatol- Matt