--- embedaddon/php/ext/pdo/pdo_sql_parser.re 2012/05/29 12:34:40 1.1.1.2 +++ embedaddon/php/ext/pdo/pdo_sql_parser.re 2014/06/15 20:03:51 1.1.1.5 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdo_sql_parser.re,v 1.1.1.2 2012/05/29 12:34:40 misho Exp $ */ +/* $Id: pdo_sql_parser.re,v 1.1.1.5 2014/06/15 20:03:51 misho Exp $ */ #include "php.h" #include "php_pdo_driver.h" @@ -32,12 +32,12 @@ #define YYCTYPE unsigned char #define YYCURSOR cursor -#define YYLIMIT cursor +#define YYLIMIT s->end #define YYMARKER s->ptr -#define YYFILL(n) +#define YYFILL(n) { RET(PDO_PARSER_EOI); } typedef struct Scanner { - char *ptr, *cur, *tok; + char *ptr, *cur, *tok, *end; } Scanner; static int scan(Scanner *s) @@ -50,21 +50,19 @@ static int scan(Scanner *s) QUESTION = [?]; COMMENTS = ("/*"([^*]+|[*]+[^/*])*[*]*"*/"|"--"[^\r\n]*); SPECIALS = [:?"']; - MULTICHAR = [:?]; - EOF = [\000]; + MULTICHAR = ([:]{2,}|[?]{2,}); ANYNOEOF = [\001-\377]; */ /*!re2c (["](([\\]ANYNOEOF)|ANYNOEOF\["\\])*["]) { RET(PDO_PARSER_TEXT); } (['](([\\]ANYNOEOF)|ANYNOEOF\['\\])*[']) { RET(PDO_PARSER_TEXT); } - MULTICHAR{2,} { RET(PDO_PARSER_TEXT); } + MULTICHAR { RET(PDO_PARSER_TEXT); } BINDCHR { RET(PDO_PARSER_BIND); } QUESTION { RET(PDO_PARSER_BIND_POS); } SPECIALS { SKIP_ONE(PDO_PARSER_TEXT); } COMMENTS { RET(PDO_PARSER_TEXT); } (ANYNOEOF\SPECIALS)+ { RET(PDO_PARSER_TEXT); } - EOF { RET(PDO_PARSER_EOI); } */ } @@ -94,6 +92,7 @@ PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *i ptr = *outquery; s.cur = inquery; + s.end = inquery + inquery_len + 1; /* phase 1: look for args */ while((t = scan(&s)) != PDO_PARSER_EOI) { @@ -229,7 +228,9 @@ safe: } plc->freeq = 1; } else { - switch (Z_TYPE_P(param->parameter)) { + zval tmp_param = *param->parameter; + zval_copy_ctor(&tmp_param); + switch (Z_TYPE(tmp_param)) { case IS_NULL: plc->quoted = "NULL"; plc->qlen = sizeof("NULL")-1; @@ -237,20 +238,20 @@ safe: break; case IS_BOOL: - convert_to_long(param->parameter); - + convert_to_long(&tmp_param); + /* fall through */ case IS_LONG: case IS_DOUBLE: - convert_to_string(param->parameter); - plc->qlen = Z_STRLEN_P(param->parameter); - plc->quoted = Z_STRVAL_P(param->parameter); - plc->freeq = 0; + convert_to_string(&tmp_param); + plc->qlen = Z_STRLEN(tmp_param); + plc->quoted = estrdup(Z_STRVAL(tmp_param)); + plc->freeq = 1; break; default: - convert_to_string(param->parameter); - if (!stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter), - Z_STRLEN_P(param->parameter), &plc->quoted, &plc->qlen, + convert_to_string(&tmp_param); + if (!stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL(tmp_param), + Z_STRLEN(tmp_param), &plc->quoted, &plc->qlen, param->param_type TSRMLS_CC)) { /* bork */ ret = -1; @@ -259,6 +260,7 @@ safe: } plc->freeq = 1; } + zval_dtor(&tmp_param); } } else { plc->quoted = Z_STRVAL_P(param->parameter); @@ -409,9 +411,9 @@ int old_pdo_parse_params(pdo_stmt_t *stmt, char *inque while (SUCCESS == zend_hash_get_current_data(params, (void**)¶m)) { if(param->parameter) { convert_to_string(param->parameter); - /* accomodate a string that needs to be fully quoted + /* accommodate a string that needs to be fully quoted bind placeholders are at least 2 characters, so - the accomodate their own "'s + the accommodate their own "'s */ newbuffer_len += padding * Z_STRLEN_P(param->parameter); }