From e3e2370490914272d7b7ca44888526d189b9e85e Mon Sep 17 00:00:00 2001 From: George Schlossnagle Date: Thu, 20 May 2004 17:34:52 +0000 Subject: [PATCH] keys need to be null-terminated (how did this not get committed before???) bind-by-name includes the leading : in the name --- ext/pdo/pdo_sql_parser.c | 14 ++++++++++---- ext/pdo/pdo_sql_parser.re | 8 +++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c index 00b131ceb7..3677157204 100644 --- a/ext/pdo/pdo_sql_parser.c +++ b/ext/pdo/pdo_sql_parser.c @@ -1,5 +1,5 @@ -/* Generated by re2c 0.5 on Tue May 18 15:32:50 2004 */ -#line 1 "/home/rei/php5/ext/pdo/pdo_sql_parser.re" +/* Generated by re2c 0.5 on Thu May 20 12:43:08 2004 */ +#line 1 "/home/george/src/pecl/pdo/pdo_sql_parser.re" /* +----------------------------------------------------------------------+ | PHP Version 5 | @@ -62,7 +62,7 @@ static int scan(Scanner *s) 160, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, - 224, 224, 224, 160, 32, 160, 160, 160, + 224, 224, 224, 160, 32, 160, 160, 224, 160, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, @@ -192,18 +192,24 @@ int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char **ou *outquery_len += (s.cur - s.tok); } else if(t == PDO_PARSER_BIND) { + char crutch; if(!params) { /* error */ efree(*outquery); return 0; } /* lookup bind first via hash and then index */ - if((SUCCESS == zend_hash_find(params, s.tok+1, s.cur-s.tok,(void **)¶m)) + /* stupid keys need to be null-terminated, even though we know their length */ + crutch = s.tok[s.cur-s.tok + 1]; + s.tok[s.cur-s.tok] = '\0'; + if((SUCCESS == zend_hash_find(params, s.tok, s.cur-s.tok + 1,(void **)¶m)) || (SUCCESS == zend_hash_index_find(params, bindno, (void **)¶m))) { char *quotedstr; int quotedstrlen; + /* restore the in-string key, doesn't need null-termination here */ + s.tok[s.cur-s.tok] = crutch; /* currently everything is a string here */ /* quote the bind value if necessary */ diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re index 22ab404e88..654d41dc49 100644 --- a/ext/pdo/pdo_sql_parser.re +++ b/ext/pdo/pdo_sql_parser.re @@ -107,18 +107,24 @@ int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char **ou *outquery_len += (s.cur - s.tok); } else if(t == PDO_PARSER_BIND) { + char crutch; if(!params) { /* error */ efree(*outquery); return 0; } /* lookup bind first via hash and then index */ - if((SUCCESS == zend_hash_find(params, s.tok+1, s.cur-s.tok,(void **)¶m)) + /* stupid keys need to be null-terminated, even though we know their length */ + crutch = s.tok[s.cur-s.tok + 1]; + s.tok[s.cur-s.tok] = '\0'; + if((SUCCESS == zend_hash_find(params, s.tok, s.cur-s.tok + 1,(void **)¶m)) || (SUCCESS == zend_hash_index_find(params, bindno, (void **)¶m))) { char *quotedstr; int quotedstrlen; + /* restore the in-string key, doesn't need null-termination here */ + s.tok[s.cur-s.tok] = crutch; /* currently everything is a string here */ /* quote the bind value if necessary */ -- 2.40.0