[GRASS-dev] Re: [bug #5341] (grass) v.db.select: segfault
Hamish
hamish_nospam at yahoo.com
Thu Nov 30 21:39:35 EST 2006
> G63> v.db.select archsites where="CAT = 1" col=cat
> cat
> 1
>
> G63> v.db.select archsites where="CAT=1" col=cat
> cat
> 11
>
> ==> that is very bad, it reports the attribute of the wrong cat !
found it.
v.db.select/main.c:
if (where_opt->answer) {
char *buf = NULL;
- buf = G_malloc ((strlen(where_opt->answer) + 7));
+ buf = G_malloc ((strlen(where_opt->answer) + 8));
sprintf (buf, " WHERE %s", where_opt->answer);
db_append_string ( &sql, buf );
G_free (buf);
}
strlen() returns the length of the string without the null terminator.
So the *buf string was allocated one smaller than it needed to be.
fixed in CVS & 6.2 branch.
Hamish
More information about the grass-dev
mailing list