$ php -r 'echo (0x00+2);echo "\n";' 4 $ php -r 'echo (0x00+ 2);echo "\n";' 2 $ php -r 'echo (0x00 + 2);echo "\n";' 2 $ php -r 'echo (0x00 +2);echo "\n";' 4 $ php -v PHP 5.3.8 (cli) (built: Dec 5 2011 21:24:09) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
ãªããªãé¢ç½ãã以ä¸ã®patchã§ããfixãã¦ããã¿ããã ãã©ã
å¤ãã³ã¼ãã¯ãã£ã¡ãææ°ã®5.3.10ã¾ã§ãã°ã£ã¦ããã
<ST_IN_SCRIPTING>{HNUM} { char *hex = yytext + 2; /* Skip "0x" */ int len = yyleng - 2; /* Skip any leading 0s */ while (*hex == '0') { hex++; len--; } if (len < SIZEOF_LONG * 2 || (len == SIZEOF_LONG * 2 && *hex <= '7')) { zendlval->value.lval = strtol(hex, NULL, 16); zendlval->type = IS_LONG; return T_LNUMBER; } else { zendlval->value.dval = zend_hex_strtod(hex, NULL); zendlval->type = IS_DOUBLE; return T_DNUMBER; } }
yytextã¯ããããã¦ããæååãå«ãã®ã ãã'\0'ã§çµäºãã¦ããããã§ã¯ãªããé·ãyylengã§åãåºãå¿ è¦ãããã¿ããã
ä¾ãã°ã
echo(0x00+2);
ã解æããã0x以éã解æããæã«yytextã¯
0x00+2);
ã¨ãªããã¾ã'0x'ãã¹ããããããã®å¾0ãã¹ããããããæ®ãã®æååã®
+2);
ãstrtolã«æ¸¡ããã¦2ã¨è©ä¾¡ããããããã¾ã§ã1ã¤ã®tokenã¨ãã¦è©ä¾¡ããããã®å¾'+','2'ãè©ä¾¡ãããã®ã§
0x2+2=2+2=4
ã¨ãªããããªãã¡ã0x00+nã¨ããæååã¯nã16é²æ°ã§è©ä¾¡ãããã®ã¨10é²æ°ã§è©ä¾¡ãããã®ã®è¶³ãç®ã«ãªãã
16é²ã¨10é²ã¨ã§å¥ã®å¤ã«ãªãæ¹ããããããã
$ php -r 'echo(0x00+10);echo("\n");' 26 $ php -r 'echo(0x00+11);echo("\n");' 28 $ php -r 'echo(0x00+100);echo("\n");' 356
ã¨ãªãã®ã¯
0x10+10=16+10=26 0x11+11=17+11=28 0x100+100=256+100=356
ã ããã
æåã®å¼ç¨ã§ç©ºç½ã®ä½ç½®ã§çµæãå¤ããã®ã¯strtolã
strtol("+2);", NULL, 16); // -> 2 strtol("+ 2);", NULL, 16); // -> 0 strtol(" +2);", NULL, 16); // -> 2 strtol(" + 2);", NULL, 16); // -> 0
ã¨è¨ç®ããããã§ããã
åæ§ã«'-n'ãstrtolã§16é²ã®-nã«è©ä¾¡ãããã®ã§
$ php -r 'echo(0x00-2);' -4 $ php -r 'echo(0x00-10);' -26
ã¨ãªã
'*n'ã'/n'ã¯strtolã§0ã«ãªã£ã¦ãã¾ãã®ã§æ®éã«0ã¨è¨ç®ããã
$ php -r 'echo(0x00*2);' 0 $ php -r 'echo(0x00*10);' 0 $ php -r 'echo(0x00/2);' 0 $ php -r 'echo(0x00/10);' 0