null+****@clear*****
null+****@clear*****
2011年 5月 27日 (金) 11:10:56 JST
Kouhei Sutou 2011-05-27 02:10:56 +0000 (Fri, 27 May 2011) New Revision: 40df0839fa21bc98ee65d1a28748f6476dc3ff10 Log: [load] add valid table name check. fixes #934 Modified files: lib/db.c test/unit/core/test-command-load.c Modified: lib/db.c (+5 -1) =================================================================== --- lib/db.c 2011-05-27 01:46:18 +0000 (c461fa2) +++ lib/db.c 2011-05-27 02:10:56 +0000 (9471747) @@ -8248,7 +8248,12 @@ grn_load(grn_ctx *ctx, grn_content_type input_type, } if (table && table_len) { grn_ctx_loader_clear(ctx); + loader->input_type = input_type; loader->table = grn_ctx_get(ctx, table, table_len); + if (!loader->table) { + ERR(GRN_INVALID_ARGUMENT, "nonexistent table: <%.*s>", table_len, table); + goto exit; + } if (loader->table && columns && columns_len) { int i, n_columns; grn_obj parsed_columns; @@ -8290,7 +8295,6 @@ grn_load(grn_ctx *ctx, grn_content_type input_type, GRN_EXPR_SYNTAX_SCRIPT|GRN_EXPR_ALLOW_UPDATE); } } - loader->input_type = input_type; } else { input_type = loader->input_type; } Modified: test/unit/core/test-command-load.c (+13 -0) =================================================================== --- test/unit/core/test-command-load.c 2011-05-27 01:46:18 +0000 (3dd09e0) +++ test/unit/core/test-command-load.c 2011-05-27 02:10:56 +0000 (ccf8ec2) @@ -37,6 +37,7 @@ void test_no_key_table(void); void test_two_bigram_indexes_to_key(void); void test_invalid_start_with_symbol(void); void test_no_key_table_without_columns(void); +void test_invalid_table_name(void); static gchar *tmp_directory; static const gchar *database_path; @@ -466,3 +467,15 @@ test_no_key_table_without_columns(void) "[3]\n" "]"); } + +void +test_invalid_table_name(void) +{ + grn_test_assert_send_command_error(context, + GRN_INVALID_ARGUMENT, + "nonexistent table: <Users>", + "load --table Users\n" + "[\n" + "[\"_key\": \"alice\"]\n" + "]"); +}