RE: [PHP-DEV] Re: [PHP-CVS] com php-src: Fix possible overflow in openssl_pbkdf2: ext/openssl/openssl.c
| From: | Anatol Belski | Date: | Tue, 18 Aug 2015 23:11:45 +0000 |
| Subject: | RE: [PHP-DEV] Re: [PHP-CVS] com php-src: Fix possible overflow in openssl_pbkdf2: ext/openssl/openssl.c | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.cvs php.internals |
| Request: | Send a blank email to internals+get-87786@lists.php.net to get a copy of this message | ||
Hi Matt,
> -----Original Message-----
> From: Matt Wilmas [mailto:php_lists@realplain.com]
> Sent: Wednesday, August 19, 2015 12:40 AM
> To: Anatol Belski <anatol.php@belski.net>; 'Jakub Zelenka'
> <bukka@php.net>
> Cc: php-cvs@lists.php.net; 'PHP internals list' <internals@lists.php.net>
> Subject: Re: [PHP-DEV] Re: [PHP-CVS] com php-src: Fix possible overflow in
> openssl_pbkdf2: ext/openssl/openssl.c
>
> Hi Anatol,
>
> ----- Original Message -----
> From: "Anatol Belski"
> Sent: Tuesday, August 18, 2015
>
> > Ok, got the idea now. But sizeof(size_t) is always >
> > sizeof(zend_long). And for signed, still it is simpler and safer to
> > just use an #ifdef around.
>
> No, == like I said. :-) OK, just saw your correction (max instead of
> sizeof); but we're never comparing a size_t with zend_long, so it doesn't
matter.
>
Yeah, I'm just too tired now, too much sizeof :)
> I don't know where you're getting zend_long from anyway. [U]INT_MAX is an
> int, not zend_long...
>
> The check in the macro, that the compiler can remove, should be fine in
all cases
> (even if *int* was 64-bit).
>
> I don't see how it's simpler or safer to use #if.
>
> But actually, if #if was used, should really be checking SIZE_MAX >
UINT_MAX I
> guess, and ZEND_LONG_MAX > INT_MAX.
>
> But using sizeof() in the macro definition gives the same result...
>
On ILP64 platform integer is 64-bit, yes. But that won't differ as that is
64-bit and unsigned (size_t) is always bigger than signed(int, zend_long,
whatever signed).
Now, what I initially was proposing - on 32-bit, #ifdef away the check about
INT_MAX < some_int, nothing else. Nothing else can be improved in those
checks (size_t > signed (int, zend_long, etc) on the same platform). It is
not a big case over all the core, but some check in the openssl ext, no
global thing here. So a simple practical solution for a concrete case :)
With your function optimization example - yeah, it will most likely be that.
However disputable in a concrete program/build, as it depends on the
optimization algo, on the data source, on the compiler itself. IMHO it is
good we have gcc or vc++, but still #ifdef excludes any interpretation and
is simple.
Good night
Anatol