Re: cvs: php-src(PHP_5_2) / NEWS /ext/standard basic_functions.c /ext/standard/tests/network ip2long_variation1.phpt

From: Date: Wed, 29 Apr 2009 12:27:12 +0000
Subject: Re: cvs: php-src(PHP_5_2) / NEWS /ext/standard basic_functions.c /ext/standard/tests/network ip2long_variation1.phpt
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-57380@lists.php.net to get a copy of this message
Hi Ilia 2009/4/29 Ilia Alshanetsky <iliaa@php.net>: > iliaa           Tue Apr 28 22:31:26 2009 UTC > >  Modified files:              (Branch: PHP_5_2) >    /php-src/ext/standard       basic_functions.c >    /php-src/ext/standard/tests/network ip2long_variation1.phpt >    /php-src    NEWS >  Log: > >  MFB: Fixed bug #47365 (ip2long() may allow some invalid values on certain >  64bit systems) > > > > http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.80&r2=1.725.2.31.2.81&diff_format=u > Index: php-src/ext/standard/basic_functions.c > diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.80 > php-src/ext/standard/basic_functions.c:1.725.2.31.2.81 > --- php-src/ext/standard/basic_functions.c:1.725.2.31.2.80      Wed Dec 31 11:17:44 2008 > +++ php-src/ext/standard/basic_functions.c      Tue Apr 28 22:31:25 2009 > @@ -17,7 +17,7 @@ >    +----------------------------------------------------------------------+ >  */ > > -/* $Id: basic_functions.c,v 1.725.2.31.2.80 2008/12/31 11:17:44 sebastian Exp $ */ > +/* $Id: basic_functions.c,v 1.725.2.31.2.81 2009/04/28 22:31:25 iliaa Exp $ */ > >  #include "php.h" >  #include "php_streams.h" > @@ -4329,38 +4329,45 @@ >  /* }}} */ >  #endif /* HAVE_INET_PTON */ > > - > - >  /* {{{ proto int ip2long(string ip_address) >    Converts a string containing an (IPv4) Internet Protocol dotted address into a proper > address */ >  PHP_FUNCTION(ip2long) >  { > -       zval **str; > +       char *addr; > +       int addr_len; > +#ifdef HAVE_INET_PTON > +       struct in_addr ip; > +#else >        unsigned long int ip; > +#endif > > -       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { > -               WRONG_PARAM_COUNT; > +       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, > &addr_len) == FAILURE) { > +               return; >        } This breaks some of the tests because they rely on the old parameter parsing API in 5_2 (Thanks Antony): ext/standard/tests/network/ip2long_error.phpt ext/standard/tests/network/ip2long_variation1.phpt > > -       convert_to_string_ex(str); > - > -       if (Z_STRLEN_PP(str) == 0 || (ip = inet_addr(Z_STRVAL_PP(str))) == INADDR_NONE) { > -               /* the only special case when we should return -1 ourselves, > +#ifdef HAVE_INET_PTON > +       if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) { > +               RETURN_FALSE; > +       } > +       RETURN_LONG(ntohl(ip.s_addr)); > +#else > +       if (addr_len == 0 || (ip = inet_addr(addr)) == INADDR_NONE) { > +               /* The only special case when we should return -1 ourselves, >                 * because inet_addr() considers it wrong. We return 0xFFFFFFFF and > -                * not -1 or ~0 because of 32/64bit issues. > -                */ > -               if (Z_STRLEN_PP(str) == sizeof("255.255..255.255") - 1 > && > -                       !memcmp(Z_STRVAL_PP(str), "255.255.255.255", > sizeof("255.255.255.255") - 1)) { > +                * not -1 or ~0 because of 32/64bit issues. */ > +               if (addr_len == sizeof("255.255.255.255") - 1 && > +                       !memcmp(addr, "255.255.255.255", > sizeof("255.255.255.255") - 1) > +               ) { >                        RETURN_LONG(0xFFFFFFFF); >                } > - >                RETURN_FALSE; >        } > - >        RETURN_LONG(ntohl(ip)); > +#endif >  } >  /* }}} */ > > + -- Kalle Sommer Nielsen kalle@php.net

« previous php.cvs (#57380) next »