From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 7625420302 for ; Wed, 23 May 2018 10:05:42 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7UQbsxaJPwT2 for ; Wed, 23 May 2018 10:05:42 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id D7797201CE for ; Wed, 23 May 2018 10:05:41 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v7 3/7] sql: introduce expr_len for sql_expr_compile Date: Wed, 23 May 2018 17:05:30 +0300 Message-Id: <074eb3156b959d1a5cc8534ec104b0bb6fc20034.1527084287.git.kshcherbatov@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Kirill Shcherbatov As we need to use parser in the cases with not null-terminated strings expr_len argument for sql_expr_compile is required. Part of #3272. --- src/box/alter.cc | 1 + src/box/sql.h | 4 +++- src/box/sql/tokenize.c | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/box/alter.cc b/src/box/alter.cc index e87bbce..e4780da 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -408,6 +408,7 @@ field_def_decode(struct field_def *field, const char **data, if (field->default_value != NULL && sql_expr_compile(sql_get(), field->default_value, + strlen(field->default_value), &field->default_value_expr) != 0) diag_raise(); } diff --git a/src/box/sql.h b/src/box/sql.h index ff8ab6f..a7f2500 100644 --- a/src/box/sql.h +++ b/src/box/sql.h @@ -74,12 +74,14 @@ struct Table; * stuct Select and return it. * @param db SQL context handle. * @param expr Expression to parse. + * @param expr_len Expression to parse length. * @param[out] result Result: AST structure. * * @retval Error code if any. */ int -sql_expr_compile(struct sqlite3 *db, const char *expr, struct Expr **result); +sql_expr_compile(struct sqlite3 *db, const char *expr, int expr_len, + struct Expr **result); /** * Store duplicate of a parsed expression into @a parser. diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index 9146e95..04e9801 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -649,16 +649,17 @@ sqlite3RunParser(Parse * pParse, const char *zSql, char **pzErrMsg) } int -sql_expr_compile(sqlite3 *db, const char *expr, struct Expr **result) +sql_expr_compile(sqlite3 *db, const char *expr, int expr_len, + struct Expr **result) { const char *outer = "SELECT "; - int len = strlen(outer) + strlen(expr); + int len = strlen(outer) + expr_len; char *stmt = (char *) region_alloc(&fiber()->gc, len + 1); if (stmt == NULL) { diag_set(OutOfMemory, len + 1, "region_alloc", "stmt"); return -1; } - sprintf(stmt, "%s%s", outer, expr); + sprintf(stmt, "%s%.*s", outer, expr_len, expr); struct Parse parser; sql_parser_create(&parser, db); -- 2.7.4