Kouhei Sutou
null+****@clear*****
Mon Mar 18 12:50:13 JST 2013
Kouhei Sutou 2013-03-18 12:50:13 +0900 (Mon, 18 Mar 2013) New Revision: f815e734af32f1817cb6bcd9829f345419bdf6a1 https://github.com/groonga/groonga/commit/f815e734af32f1817cb6bcd9829f345419bdf6a1 Message: Fix a crash bug `select --output_columns '_key.garbage'` crashes groonga. If `garbage` does not exist, it is just ignored as same as other cases. Added files: test/command/suite/select/output_columns/key/chained_not_exist.test Copied files: test/command/suite/select/output_columns/key/chained_not_exist.expected (from test/command/suite/select/output_columns/score/chained.expected) Modified files: lib/db.c test/command/suite/select/output_columns/score/chained.expected Modified: lib/db.c (+14 -2) =================================================================== --- lib/db.c 2013-03-14 23:02:17 +0900 (bbbdf81) +++ lib/db.c 2013-03-18 12:50:13 +0900 (d3d8506) @@ -3832,9 +3832,11 @@ static grn_obj * grn_obj_get_accessor(grn_ctx *ctx, grn_obj *obj, const char *name, unsigned int name_size) { grn_accessor *res = NULL, **rp = NULL, **rp0 = NULL; + grn_bool is_chained = GRN_FALSE; if (!obj) { return NULL; } GRN_API_ENTER; if (obj->header.type == GRN_ACCESSOR) { + is_chained = GRN_TRUE; for (rp0 = (grn_accessor **)&obj; *rp0; rp0 = &(*rp0)->next) { res = *rp0; } @@ -4095,7 +4097,9 @@ grn_obj_get_accessor(grn_ctx *ctx, grn_obj *obj, const char *name, unsigned int } else { if (!obj->header.domain) { // ERR(GRN_INVALID_ARGUMENT, "no such column: <%s>", name); - grn_obj_close(ctx, (grn_obj *)res); + if (!is_chained) { + grn_obj_close(ctx, (grn_obj *)res); + } res = NULL; goto exit; } @@ -4122,7 +4126,15 @@ grn_obj_get_accessor(grn_ctx *ctx, grn_obj *obj, const char *name, unsigned int } } } - if (sp != se) { grn_obj_get_accessor(ctx, (grn_obj *)res, sp, se - sp); } + if (sp != se) { + if (!grn_obj_get_accessor(ctx, (grn_obj *)res, sp, se - sp)) { + if (!is_chained) { + grn_obj_close(ctx, (grn_obj *)res); + res = NULL; + goto exit; + } + } + } } if (rp0) { *rp0 = res; } exit : Copied: test/command/suite/select/output_columns/key/chained_not_exist.expected (+2 -2) 55% =================================================================== --- test/command/suite/select/output_columns/score/chained.expected 2013-03-14 23:02:17 +0900 (382a907) +++ test/command/suite/select/output_columns/key/chained_not_exist.expected 2013-03-18 12:50:13 +0900 (ba36bd5) @@ -6,5 +6,5 @@ load --table Sites ["http://groonga.org/"] ] [[0,0.0,0.0],1] -select Sites --filter true --output_columns '_score.garbage' -[[0,0.0,0.0],[[[1],[["_score","Int32"]],[1]]]] +select Sites --filter true --output_columns '_key.garbage' +[[0,0.0,0.0],[[[1],[],[]]]] Added: test/command/suite/select/output_columns/key/chained_not_exist.test (+9 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/output_columns/key/chained_not_exist.test 2013-03-18 12:50:13 +0900 (a76cff5) @@ -0,0 +1,9 @@ +table_create Sites TABLE_HASH_KEY ShortText + +load --table Sites +[ +["_key"], +["http://groonga.org/"] +] + +select Sites --filter true --output_columns '_key.garbage' Modified: test/command/suite/select/output_columns/score/chained.expected (+1 -1) =================================================================== --- test/command/suite/select/output_columns/score/chained.expected 2013-03-14 23:02:17 +0900 (382a907) +++ test/command/suite/select/output_columns/score/chained.expected 2013-03-18 12:50:13 +0900 (f847ca3) @@ -7,4 +7,4 @@ load --table Sites ] [[0,0.0,0.0],1] select Sites --filter true --output_columns '_score.garbage' -[[0,0.0,0.0],[[[1],[["_score","Int32"]],[1]]]] +[[0,0.0,0.0],[[[1],[],[]]]] -------------- next part -------------- HTML����������������������������...Download