[GRASS-dev] Re: [GRASS GIS] #461: v.to.db crashes on a shapefile
connected with v.external
GRASS GIS
trac at osgeo.org
Thu Jan 14 06:42:49 EST 2010
#461: v.to.db crashes on a shapefile connected with v.external
-----------------------+----------------------------------------------------
Reporter: msieczka | Owner: grass-dev at lists.osgeo.org
Type: defect | Status: new
Priority: critical | Milestone: 6.4.0
Component: Vector | Version: svn-develbranch6
Resolution: | Keywords:
Platform: Linux | Cpu: x86-64
-----------------------+----------------------------------------------------
Comment (by mmetz):
Replying to [comment:8 mmetz]:
>
> Going a bit further to the root of the problem: in this case const char
*col passed to db_select_int() in lib/db/dbmi_client/select.c is a zero
length string, you could do for 'col' the same test that's done for
'where' and exit with an error.
The following patch works for me
{{{
Index: select.c
===================================================================
--- select.c (revision 40416)
+++ select.c (working copy)
@@ -115,6 +115,9 @@
G_debug(3, "db_select_int()");
+ if (col == NULL || strlen(col) == 0)
+ G_fatal_error(_("Missing column name"));
+
/* allocate */
alloc = 1000;
val = (int *)G_malloc(alloc * sizeof(int));
@@ -203,6 +206,12 @@
dbValue *value;
dbTable *table;
+ if (key == NULL || strlen(key) == 0)
+ G_fatal_error(_("Missing key column name"));
+
+ if (col == NULL || strlen(col) == 0)
+ G_fatal_error(_("Missing column name"));
+
G_zero(val, sizeof(dbValue));
sprintf(buf, "SELECT %s FROM %s WHERE %s = %d\n", col, tab, key, id);
db_init_string(&stmt);
@@ -259,6 +268,12 @@
G_debug(3, "db_select_db_select_CatValArray ()");
+ if (key == NULL || strlen(key) == 0)
+ G_fatal_error(_("Missing key column name"));
+
+ if (col == NULL || strlen(col) == 0)
+ G_fatal_error(_("Missing column name"));
+
db_init_string(&stmt);
sprintf(buf, "SELECT %s, %s FROM %s", key, col, tab);
}}}
Problem is when a module gives a broken sql string to
db_execute_immediate(), hopefully that aborts with an error and not a
segfault.
Glynn's patch could be useful in other circumstances too.
Markus M
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/461#comment:9>
GRASS GIS <http://grass.osgeo.org>
More information about the grass-dev
mailing list