[Groonga-commit] groonga/groonga at 69b1a0e [master] Fix a crash bug when grn_obj_path() is called for a built-in proc

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Jul 6 22:39:54 JST 2013


Kouhei Sutou	2013-07-06 22:39:54 +0900 (Sat, 06 Jul 2013)

  New Revision: 69b1a0e92ed0249165cdb6b209181c6cea961fdc
  https://github.com/groonga/groonga/commit/69b1a0e92ed0249165cdb6b209181c6cea961fdc

  Message:
    Fix a crash bug when grn_obj_path() is called for a built-in proc
    
    For example, "select" is a built-in proc.
    
    Reported by Genki Takiuchi. Thanks!!!

  Added files:
    test/unit/core/test-proc.c
  Modified files:
    lib/plugin.c
    test/unit/core/Makefile.am

  Modified: lib/plugin.c (+4 -0)
===================================================================
--- lib/plugin.c    2013-07-03 17:29:33 +0900 (9afafb7)
+++ lib/plugin.c    2013-07-06 22:39:54 +0900 (95733a5)
@@ -65,6 +65,10 @@ grn_plugin_path(grn_ctx *ctx, grn_id id)
   size_t system_plugins_dir_size;
 
   path = _grn_hash_key(ctx, grn_plugins, id, &key_size);
+  if (!path) {
+    return NULL;
+  }
+
   system_plugins_dir = grn_plugin_get_system_plugins_dir();
   system_plugins_dir_size = strlen(system_plugins_dir);
   if (strncmp(system_plugins_dir, path, system_plugins_dir_size) == 0) {

  Modified: test/unit/core/Makefile.am (+3 -1)
===================================================================
--- test/unit/core/Makefile.am    2013-07-03 17:29:33 +0900 (9423c7b)
+++ test/unit/core/Makefile.am    2013-07-06 22:39:54 +0900 (d5a6bac)
@@ -63,7 +63,8 @@ noinst_LTLIBRARIES =				\
 	test-accessor.la			\
 	test-object.la				\
 	test-rename.la				\
-	test-tokenizer.la
+	test-tokenizer.la			\
+	test-proc.la
 endif
 
 AM_CPPFLAGS =			\
@@ -152,3 +153,4 @@ test_accessor_la_SOURCES		= test-accessor.c
 test_object_la_SOURCES			= test-object.c
 test_rename_la_SOURCES			= test-rename.c
 test_tokenizer_la_SOURCES		= test-tokenizer.c
+test_proc_la_SOURCES			= test-proc.c

  Added: test/unit/core/test-proc.c (+113 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-proc.c    2013-07-06 22:39:54 +0900 (ed028d5)
@@ -0,0 +1,113 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2013  Kouhei Sutou <kou �� clear-code.com>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include <groonga.h>
+
+#include <gcutter.h>
+#include <glib/gstdio.h>
+
+#include "../lib/grn-assertions.h"
+
+void data_path(void);
+void test_path(gconstpointer data);
+
+static gchar *tmp_directory;
+
+static grn_logger_info *logger;
+static grn_ctx *context;
+static grn_obj *database, *proc;
+
+void
+cut_startup(void)
+{
+  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
+                                   "test-proc",
+                                   NULL);
+}
+
+void
+cut_shutdown(void)
+{
+  g_free(tmp_directory);
+}
+
+static void
+remove_tmp_directory(void)
+{
+  cut_remove_path(tmp_directory, NULL);
+}
+
+void
+cut_setup(void)
+{
+  remove_tmp_directory();
+  g_mkdir_with_parents(tmp_directory, 0700);
+
+  context = NULL;
+  logger = setup_grn_logger();
+
+  context = g_new0(grn_ctx, 1);
+  grn_ctx_init(context, 0);
+
+  database = grn_db_create(context,
+                           cut_build_path(tmp_directory, "proc.db", NULL),
+                           NULL);
+
+  proc = NULL;
+}
+
+void
+cut_teardown(void)
+{
+  if (proc) {
+    grn_obj_unlink(context, proc);
+  }
+
+  grn_obj_close(context, database);
+  grn_ctx_fin(context);
+  g_free(context);
+
+  teardown_grn_logger(logger);
+  cut_remove_path(tmp_directory, NULL);
+}
+
+void
+data_path(void)
+{
+#define ADD_DATA(label, expected, name)                 \
+  gcut_add_datum(label,                                 \
+                 "expected", G_TYPE_STRING, expected,   \
+                 "name", G_TYPE_STRING, name,           \
+                 NULL)
+
+  ADD_DATA("built-in", NULL, "select");
+
+#undef ADD_DATA
+}
+
+void
+test_path(gconstpointer data)
+{
+  const gchar *expected;
+  const gchar *name;
+
+  expected = gcut_data_get_string(data, "expected");
+  name = gcut_data_get_string(data, "name");
+  proc = grn_ctx_get(context, name, -1);
+  cut_assert_equal_string(expected, grn_obj_path(context, proc));
+}
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index