Kouhei Sutou
null+****@clear*****
Tue Jul 1 09:17:45 JST 2014
Kouhei Sutou 2014-07-01 09:17:45 +0900 (Tue, 01 Jul 2014) New Revision: 0444c4805cbd56faca52a01a7d55f63cab7b6dc5 https://github.com/groonga/groonga/commit/0444c4805cbd56faca52a01a7d55f63cab7b6dc5 Message: select adjuster: add an error check to avoid crash Added files: test/command/suite/select/adjuster/invalid/missing_plus.expected test/command/suite/select/adjuster/invalid/missing_plus.test Modified files: lib/proc.c Modified: lib/proc.c (+10 -4) =================================================================== --- lib/proc.c 2014-06-29 23:10:06 +0900 (f61fed9) +++ lib/proc.c 2014-07-01 09:17:45 +0900 (e525416) @@ -717,16 +717,20 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len, result_size += ngkeys; } } - GRN_OUTPUT_ARRAY_OPEN("RESULT", result_size); if (adjuster && adjuster_len) { grn_obj *adjuster_; grn_obj *v; GRN_EXPR_CREATE_FOR_QUERY(ctx, table_, adjuster_, v); if (adjuster_ && v) { - grn_expr_parse(ctx, adjuster_, adjuster, adjuster_len, NULL, - GRN_OP_MATCH, GRN_OP_ADJUST, - GRN_EXPR_SYNTAX_ADJUSTER); + grn_rc rc; + rc = grn_expr_parse(ctx, adjuster_, adjuster, adjuster_len, NULL, + GRN_OP_MATCH, GRN_OP_ADJUST, + GRN_EXPR_SYNTAX_ADJUSTER); + if (rc) { + grn_obj_unlink(ctx, adjuster_); + goto exit; + } cacheable *= ((grn_expr *)adjuster_)->cacheable; taintable += ((grn_expr *)adjuster_)->taintable; grn_select_apply_adjuster(ctx, table_, res, adjuster_); @@ -759,6 +763,8 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len, ":", "score(%d)", nhits); } + GRN_OUTPUT_ARRAY_OPEN("RESULT", result_size); + grn_normalize_offset_and_limit(ctx, nhits, &offset, &limit); if (sortby_len && Added: test/command/suite/select/adjuster/invalid/missing_plus.expected (+43 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/adjuster/invalid/missing_plus.expected 2014-07-01 09:17:45 +0900 (f6aa8c7) @@ -0,0 +1,43 @@ +table_create Tags TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags +[[0,0.0,0.0],true] +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags +[[0,0.0,0.0],true] +load --table Memos +[ +{ + "_key": "Groonga is fast", + "tags": { + "groonga": 100 + } +}, +{ + "_key": "Mroonga is also fast", + "tags": { + "mroonga": 100, + "groonga": 10 + } +}, +{ + "_key": "Ruby is an object oriented script language", + "tags": { + "ruby": 100 + } +} +] +[[0,0.0,0.0],3] +select Memos --filter true --adjuster 'tags @ "groonga" * 4 tags @ "mroonga" * 3' --output_columns _key,_score +[ + [ + [ + -63, + 0.0, + 0.0 + ], + "Syntax error! (tags @ \"groonga\" * 4 tags @ \"mroonga\" * 3)" + ] +] +#|e| Syntax error! (tags @ "groonga" * 4 tags @ "mroonga" * 3) Added: test/command/suite/select/adjuster/invalid/missing_plus.test (+34 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/adjuster/invalid/missing_plus.test 2014-07-01 09:17:45 +0900 (07f169b) @@ -0,0 +1,34 @@ +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags + +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags + +load --table Memos +[ +{ + "_key": "Groonga is fast", + "tags": { + "groonga": 100 + } +}, +{ + "_key": "Mroonga is also fast", + "tags": { + "mroonga": 100, + "groonga": 10 + } +}, +{ + "_key": "Ruby is an object oriented script language", + "tags": { + "ruby": 100 + } +} +] + +select Memos \ + --filter true \ + --adjuster 'tags @ "groonga" * 4 tags @ "mroonga" * 3' \ + --output_columns _key,_score -------------- next part -------------- HTML����������������������������...Download