]> granicus.if.org Git - php/commitdiff
keys need to be null-terminated (how did this not get committed before???)
authorGeorge Schlossnagle <gschlossnagle@php.net>
Thu, 20 May 2004 17:34:52 +0000 (17:34 +0000)
committerGeorge Schlossnagle <gschlossnagle@php.net>
Thu, 20 May 2004 17:34:52 +0000 (17:34 +0000)
bind-by-name includes the leading : in the name

ext/pdo/pdo_sql_parser.c
ext/pdo/pdo_sql_parser.re

index 00b131ceb732ed34af446a3c9855608a6cf766da..3677157204ab32798c5373938b62c2e51bb14c84 100644 (file)
@@ -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 **)&param))  
+                       /* 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 **)&param))  
                            ||
                           (SUCCESS == zend_hash_index_find(params, bindno, (void **)&param))) 
                        {
                                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 */
index 22ab404e88192319e17f77dc1c0af737f31a5286..654d41dc49d4dd434822999942e5ebf9a551d426 100644 (file)
@@ -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 **)&param))  
+                       /* 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 **)&param))  
                            ||
                           (SUCCESS == zend_hash_index_find(params, bindno, (void **)&param))) 
                        {
                                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 */