[Groonga-commit] pgroonga/pgroonga at af2d78b [master] Add missing empty array check

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Oct 7 16:48:12 JST 2017


Kouhei Sutou	2017-10-07 16:48:12 +0900 (Sat, 07 Oct 2017)

  New Revision: af2d78b6a940d9afbbe2cff85fecdd76d4db75f7
  https://github.com/pgroonga/pgroonga/commit/af2d78b6a940d9afbbe2cff85fecdd76d4db75f7

  Message:
    Add missing empty array check
    
    The following commands might enter long loop:
    
      * pgroonga_snippet_html
      * pgroonga_highlight_html
      * pgroonga_command

  Modified files:
    src/pgrn-keywords.c
    src/pgrn-query-expand.c
    src/pgrn-snippet-html.c
    src/pgroonga.c

  Modified: src/pgrn-keywords.c (+4 -1)
===================================================================
--- src/pgrn-keywords.c    2017-10-07 13:55:20 +0900 (ccbab4d)
+++ src/pgrn-keywords.c    2017-10-07 16:48:12 +0900 (dac2710)
@@ -30,7 +30,10 @@ PGrnKeywordsUpdateTable(ArrayType *keywords, grn_obj *keywordsTable)
 
 		GRN_BULK_REWIND(&keywordIDs);
 
-		n = ARR_DIMS(keywords)[0];
+		if (ARR_NDIM(keywords) == 0)
+			n = 0;
+		else
+			n = ARR_DIMS(keywords)[0];
 		for (i = 1; i <= n; i++)
 		{
 			Datum keywordDatum;

  Modified: src/pgrn-query-expand.c (+3 -0)
===================================================================
--- src/pgrn-query-expand.c    2017-10-07 13:55:20 +0900 (fa6cb91)
+++ src/pgrn-query-expand.c    2017-10-07 16:48:12 +0900 (3978fe3)
@@ -120,6 +120,9 @@ func_query_expander_postgresql(grn_ctx *ctx,
 			int i, n;
 
 			synonymsArray = DatumGetArrayTypeP(synonymsDatum);
+			if (ARR_NDIM(synonymsArray) == 0)
+				continue;
+
 			n = ARR_DIMS(synonymsArray)[0];
 			if (n == 0)
 				continue;

  Modified: src/pgrn-snippet-html.c (+4 -1)
===================================================================
--- src/pgrn-snippet-html.c    2017-10-07 13:55:20 +0900 (c8e5079)
+++ src/pgrn-snippet-html.c    2017-10-07 16:48:12 +0900 (bbed99f)
@@ -42,7 +42,10 @@ PGrnSnipCreate(ArrayType *keywords)
 	{
 		int i, n;
 
-		n = ARR_DIMS(keywords)[0];
+		if (ARR_NDIM(keywords) == 0)
+			n = 0;
+		else
+			n = ARR_DIMS(keywords)[0];
 		for (i = 1; i <= n; i++)
 		{
 			Datum keywordDatum;

  Modified: src/pgroonga.c (+4 -4)
===================================================================
--- src/pgroonga.c    2017-10-07 13:55:20 +0900 (7e94b02)
+++ src/pgroonga.c    2017-10-07 16:48:12 +0900 (a7bbfe5)
@@ -1370,10 +1370,10 @@ pgroonga_command(PG_FUNCTION_ARGS)
 		ArrayType *arguments = PG_GETARG_ARRAYTYPE_P(1);
 		int i, n;
 
-		n = ARR_DIMS(arguments)[0];
-		if ((n % 2) != 0)
-		{
-		}
+		if (ARR_NDIM(arguments) == 0)
+			n = 0;
+		else
+			n = ARR_DIMS(arguments)[0];
 
 		grn_obj_reinit(ctx, command, GRN_DB_TEXT, 0);
 		GRN_TEXT_PUT(ctx,
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171007/60d50418/attachment-0001.htm 



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