null+****@clear*****
null+****@clear*****
2010年 10月 8日 (金) 12:09:32 JST
Kouhei Sutou 2010-10-08 03:09:32 +0000 (Fri, 08 Oct 2010)
New Revision: 756d41147c1132e311630252f8582e23bb650855
Log:
check function availability. #596
Added files:
test/unit/core/test-command-select-filter-invalid.c
Modified files:
lib/expr.c
test/unit/core/Makefile.am
Modified: lib/expr.c (+31 -0)
===================================================================
--- lib/expr.c 2010-10-06 01:27:38 +0000 (457ed83)
+++ lib/expr.c 2010-10-08 03:09:32 +0000 (d32ea0e)
@@ -21,6 +21,15 @@
#include <float.h>
#include "ii.h"
#include "geo.h"
+#include "util.h"
+
+static inline int
+function_proc_p(grn_obj *expr)
+{
+ return (expr &&
+ expr->header.type == GRN_PROC &&
+ ((grn_proc *)expr)->type == GRN_PROC_FUNCTION);
+}
grn_obj *
grn_expr_alloc(grn_ctx *ctx, grn_obj *expr, grn_id domain, grn_obj_flags flags)
@@ -2199,6 +2208,28 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs)
goto exit;
}
proc = sp[-offset];
+ if (!function_proc_p(proc)) {
+ grn_obj buffer;
+
+ GRN_TEXT_INIT(&buffer, 0);
+ switch (proc->header.type) {
+ case GRN_TABLE_HASH_KEY:
+ case GRN_TABLE_PAT_KEY:
+ case GRN_TABLE_NO_KEY:
+ case GRN_COLUMN_FIX_SIZE:
+ case GRN_COLUMN_VAR_SIZE:
+ case GRN_COLUMN_INDEX:
+ grn_inspect_name(ctx, &buffer, proc);
+ break;
+ default:
+ grn_inspect(ctx, &buffer, proc);
+ break;
+ }
+ ERR(GRN_INVALID_ARGUMENT, "invalid function: <%.*s>",
+ GRN_TEXT_LEN(&buffer), GRN_TEXT_VALUE(&buffer));
+ GRN_OBJ_FIN(ctx, &buffer);
+ goto exit;
+ }
WITH_SPSAVE({
grn_proc_call(ctx, proc, code->nargs, expr);
});
Modified: test/unit/core/Makefile.am (+2 -0)
===================================================================
--- test/unit/core/Makefile.am 2010-10-06 01:27:38 +0000 (f1d7e1a)
+++ test/unit/core/Makefile.am 2010-10-08 03:09:32 +0000 (b3fe5a7)
@@ -46,6 +46,7 @@ noinst_LTLIBRARIES = \
test-command-select.la \
test-command-select-sort.la \
test-command-select-prefix-search.la \
+ test-command-select-filter-invalid.la \
test-command-define-selector.la \
test-command-cache-limit.la \
test-command-delete.la \
@@ -121,6 +122,7 @@ test_command_column_list_la_SOURCES = test-command-column-list.c
test_command_select_la_SOURCES = test-command-select.c
test_command_select_sort_la_SOURCES = test-command-select-sort.c
test_command_select_prefix_search_la_SOURCES = test-command-select-prefix-search.c
+test_command_select_filter_invalid_la_SOURCES = test-command-select-filter-invalid.c
test_command_define_selector_la_SOURCES = test-command-define-selector.c
test_command_cache_limit_la_SOURCES = test-command-cache-limit.c
test_command_delete_la_SOURCES = test-command-delete.c
Added: test/unit/core/test-command-select-filter-invalid.c (+103 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-command-select-filter-invalid.c 2010-10-08 03:09:32 +0000 (5e5e76b)
@@ -0,0 +1,103 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+ Copyright(C) 2010 Kouhei Sutou <kou****@clear*****>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License version 2.1 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "str.h"
+#include <stdio.h>
+
+#include <gcutter.h>
+
+#include "../lib/grn-assertions.h"
+
+void test_no_operator_and_parentheses_column(void);
+
+static gchar *tmp_directory;
+
+static grn_ctx *context;
+static grn_obj *database;
+
+void
+cut_startup(void)
+{
+ tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
+ "command-select-filter-invalid",
+ NULL);
+}
+
+void
+cut_shutdown(void)
+{
+ g_free(tmp_directory);
+}
+
+static void
+remove_tmp_directory(void)
+{
+ cut_remove_path(tmp_directory, NULL);
+}
+
+static void
+setup_data(void)
+{
+ assert_send_commands("table_create Sites TABLE_HASH_KEY ShortText\n"
+ "column_create Sites uri COLUMN_SCALAR ShortText\n"
+ "load --table Sites\n"
+ "[\n"
+ "[\"_key\",\"uri\"],\n"
+ "[\"groonga\",\"http://groonga.org/\"],\n"
+ "[\"razil\",\"http://razil.jp/\"]\n"
+ "]");
+}
+
+void
+cut_setup(void)
+{
+ const gchar *database_path;
+
+ remove_tmp_directory();
+ g_mkdir_with_parents(tmp_directory, 0700);
+
+ context = g_new0(grn_ctx, 1);
+ grn_ctx_init(context, 0);
+
+ database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
+ database = grn_db_create(context, database_path, NULL);
+
+ setup_data();
+}
+
+void
+cut_teardown(void)
+{
+ if (context) {
+ grn_obj_unlink(context, database);
+ grn_ctx_fin(context);
+ g_free(context);
+ }
+
+ remove_tmp_directory();
+}
+
+void
+test_no_operator_and_parentheses_column(void)
+{
+ grn_test_assert_send_command_error(
+ context,
+ GRN_SUCCESS,
+ "invalid function: <\"groonga\">",
+ "select Sites --filter \"_key != \\\"groonga\\\" ()\"");
+}