[Groonga-commit] groonga/groonga [master] [cast][geo] add missing end point check.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 8月 31日 (水) 15:50:45 JST


Kouhei Sutou	2011-08-31 06:50:45 +0000 (Wed, 31 Aug 2011)

  New Revision: ac797c1292181e3e887deb088f7c4afad2f963fd

  Log:
    [cast][geo] add missing end point check.
    
    This fix the following case:
    
      grn_obj buffer, dest;
      GRN_TEXT_INIT(&buffer, 0);
      GRN_TEXT_PUTS(ctx, &buffer, "130194581x503802073.0");
      GRN_BULK_REWIND(&buffer);
      GRN_TEXT_PUTS(ctx, &buffer, "130194581x503802073");
      GRN_TOKYO_GEO_POINT_INIT(&dest, 0);
      grn_obj_cast(ctx, &buffer, &dest, GRN_FALSE);

  Modified files:
    lib/db.c
    test/unit/core/test-cast-basic.c

  Modified: lib/db.c (+2 -2)
===================================================================
--- lib/db.c    2011-08-29 00:36:04 +0000 (49417b5)
+++ lib/db.c    2011-08-31 06:50:45 +0000 (b8fadc4)
@@ -4221,7 +4221,7 @@ grn_obj_cast(grn_ctx *ctx, grn_obj *src, grn_obj *dest, int addp)
         char *end;
         grn_obj buf, *buf_p = NULL;
         latitude = grn_atoi(str, str_end, &cur);
-        if (cur[0] == '.') {
+        if (cur < str_end && cur[0] == '.') {
           GRN_TEXT_INIT(&buf, 0);
           GRN_TEXT_PUT(ctx, &buf, str, GRN_TEXT_LEN(src));
           GRN_TEXT_PUTC(ctx, &buf, '\0');
@@ -4238,7 +4238,7 @@ grn_obj_cast(grn_ctx *ctx, grn_obj *src, grn_obj *dest, int addp)
         if (!rc && (cur[0] == 'x' || cur[0] == ',') && cur + 1 < str_end) {
           const char *c = cur + 1;
           longitude = grn_atoi(c, str_end, &cur);
-          if (cur[0] == '.') {
+          if (cur < str_end && cur[0] == '.') {
             if (!buf_p) {
               GRN_TEXT_INIT(&buf, 0);
               GRN_TEXT_PUT(ctx, &buf, str, GRN_TEXT_LEN(src));

  Modified: test/unit/core/test-cast-basic.c (+16 -0)
===================================================================
--- test/unit/core/test-cast-basic.c    2011-08-29 00:36:04 +0000 (e1ac888)
+++ test/unit/core/test-cast-basic.c    2011-08-31 06:50:45 +0000 (922a7dd)
@@ -36,6 +36,7 @@ void test_text_to_uint64(void);
 void test_text_to_float(void);
 void test_text_to_time(void);
 void test_text_to_geo_point(void);
+void test_text_to_geo_point_garbage(void);
 void test_text_to_geo_point_comma(void);
 void test_text_to_geo_point_invalid(void);
 void test_text_to_geo_point_in_degree(void);
@@ -266,6 +267,21 @@ test_text_to_geo_point(void)
 }
 
 void
+test_text_to_geo_point_garbage(void)
+{
+  gint takane_latitude, takane_longitude;
+
+  grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0);
+#define GEO_TEXT "130194581x503802073"
+  set_text(GEO_TEXT ".0");
+  cast_text(GEO_TEXT);
+#undef GEO_TEXT
+  GRN_GEO_POINT_VALUE(&dest, takane_latitude, takane_longitude);
+  cut_assert_equal_int(130194581, takane_latitude);
+  cut_assert_equal_int(503802073, takane_longitude);
+}
+
+void
 test_text_to_geo_point_comma(void)
 {
   gint takane_latitude, takane_longitude;




Groonga-commit メーリングリストの案内
Back to archive index