null+****@clear*****
null+****@clear*****
2010年 10月 22日 (金) 15:20:39 JST
Kouhei Sutou 2010-10-22 06:20:39 +0000 (Fri, 22 Oct 2010)
New Revision: 5d25de3233d4148b9294b30cde9557c21fbaab55
Log:
fix dump SEGV by orphan pat record reference. #630
Modified files:
lib/pat.c
test/unit/core/test-dump.c
Modified: lib/pat.c (+8 -2)
===================================================================
--- lib/pat.c 2010-10-22 06:47:39 +0000 (1ad7810)
+++ lib/pat.c 2010-10-22 06:20:39 +0000 (0fd8910)
@@ -1165,13 +1165,19 @@ const char *
_grn_pat_key(grn_ctx *ctx, grn_pat *pat, grn_id id, uint32_t *key_size)
{
pat_node *node;
+ uint8_t *key;
PAT_AT(pat, id, node);
if (!node) {
*key_size = 0;
return NULL;
}
- *key_size = PAT_LEN(node);
- return (const char *) pat_node_get_key(ctx, pat, node);
+ key = pat_node_get_key(ctx, pat, node);
+ if (key) {
+ *key_size = PAT_LEN(node);
+ } else {
+ *key_size = 0;
+ }
+ return (const char *)key;
}
grn_rc
Modified: test/unit/core/test-dump.c (+39 -0)
===================================================================
--- test/unit/core/test-dump.c 2010-10-22 06:47:39 +0000 (7a1ccd2)
+++ test/unit/core/test-dump.c 2010-10-22 06:20:39 +0000 (d632453)
@@ -33,6 +33,7 @@ void data_vector_column(void);
void test_uvector_column(gconstpointer data);
void test_vector_column(gconstpointer data);
void test_unsequantial_records_in_table_with_keys(void);
+void test_nil_reference(void);
static grn_logger_info *logger;
static grn_ctx *context;
@@ -469,3 +470,41 @@ test_unsequantial_records_in_table_with_keys(void)
"]",
send_command("dump"));
}
+
+void
+test_nil_reference(void)
+{
+ assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
+ assert_send_command("table_create Initials TABLE_PAT_KEY ShortText");
+ assert_send_command("column_create Users initial COLUMN_SCALAR Initials");
+
+ cut_assert_equal_string(
+ "2",
+ send_command("load --table Initials --columns '_key'\n"
+ "[\n"
+ " [\"U\"],\n"
+ " [\"ア\"]\n"
+ "]"));
+ cut_assert_equal_string(
+ "1",
+ send_command("load --table Users --columns '_key'\n"
+ "[\n"
+ " [\"mori\"]\n"
+ "]"));
+
+ cut_assert_equal_string("table_create Users TABLE_HASH_KEY ShortText\n"
+ "table_create Initials TABLE_PAT_KEY ShortText\n"
+ "column_create Users initial COLUMN_SCALAR Initials\n"
+ "load --table Users\n"
+ "[\n"
+ "[\"_key\",\"initial\"],\n"
+ "[\"mori\",\"\"]\n"
+ "]\n"
+ "load --table Initials\n"
+ "[\n"
+ "[\"_key\"],\n"
+ "[\"U\"],\n"
+ "[\"ア\"]\n"
+ "]",
+ send_command("dump"));
+}