null+****@clear*****
null+****@clear*****
2011年 11月 7日 (月) 16:41:18 JST
Susumu Yata 2011-11-07 07:41:18 +0000 (Mon, 07 Nov 2011) New Revision: de39f3f606c28229cfab1b464e641fbf625234c8 Log: add tests to detect a too long path. Modified files: lib/plugin.c Modified: lib/plugin.c (+14 -0) =================================================================== --- lib/plugin.c 2011-11-07 06:19:17 +0000 (3590501) +++ lib/plugin.c 2011-11-07 07:41:18 +0000 (f708498) @@ -270,12 +270,21 @@ grn_plugin_register_by_path(grn_ctx *ctx, const char *path) grn_id id = GRN_ID_NIL; FILE *plugin_file; char complemented_path[PATH_MAX], complemented_libs_path[PATH_MAX]; + size_t path_len; + if ((path_len = strlen(path)) >= PATH_MAX) { + ERR(GRN_FILENAME_TOO_LONG, "too long path"); + GRN_API_RETURN(ctx->rc); + } plugin_file = fopen(path, "r"); if (plugin_file) { fclose(plugin_file); id = grn_plugin_open(ctx, path); } else { + if ((path_len += strlen(grn_plugin_get_suffix())) >= PATH_MAX) { + ERR(GRN_FILENAME_TOO_LONG, "too long path"); + GRN_API_RETURN(ctx->rc); + } strcpy(complemented_path, path); strcat(complemented_path, grn_plugin_get_suffix()); plugin_file = fopen(complemented_path, "r"); @@ -290,6 +299,11 @@ grn_plugin_register_by_path(grn_ctx *ctx, const char *path) base_name = strrchr(path, '/'); if (base_name) { + path_len = base_name - path + strlen("/.libs") + strlen(base_name); + if ((path_len += strlen(grn_plugin_get_suffix())) >= PATH_MAX) { + ERR(GRN_FILENAME_TOO_LONG, "too long path"); + GRN_API_RETURN(ctx->rc); + } complemented_libs_path[0] = '\0'; strncat(complemented_libs_path, path, base_name - path); strcat(complemented_libs_path, "/.libs");