[GRASS5] Re: [bug #1052] (grass) [rsv].proj are crashing

Markus Neteler neteler at itc.it
Thu May 23 04:26:14 EDT 2002


On Wed, May 22, 2002 at 11:41:40PM +0100, Glynn Clements wrote:
> 
> Markus Neteler wrote:
> 
> > > > If strcmp() crashes, one of its arguments is invalid, in the sense
> > > > that either:
> > > > 
> > > > a) it points to an invalid address (e.g. NULL), or
> > > > b) it points to a valid address, but scanning the string reaches an
> > > > invalid address before it reads a terminating NUL byte.
> > > > 
> > > > So, something is passing bad values to strcmp(). In this instance,
> > > > either the "environment" is bad, or the caller is passing a bad "name"
> > > > argument to G_getenv() or similar.
> > > 
> > > Here is the output of g.gisenv:
> > > 
> > > g.gisenv
> > > LOCATION_NAME=sjtsk
> > > MAPSET=neteler
> > > DIGITIZER=none
> > > GISDBASE=/ssi0/ssi/blazek/pub
> > > MONITOR=x0
> > > GRASS_GUI=text
> > > 
> > > which looks o.k. Also during the debugging the values seemed to
> > > be always set.
> > > 
> > > Is there anyone else who could try the latest [rvs].proj from
> > > CVS (pre4 or HEAD)?
> > 
> > A followup: I had added some debug output into the function in
> > env.c:
> 
> [snip]
> 
> Your debug output doesn't make much sense.

Possible.
So I have continued.

> > In general the function seems to work well (it is used often,
> > only it suddenly crashes).
> 
> Basically, there are two likely possibilities. Either something is
> corrupting the environment array, or something is passing a bad
> argument to G_getenv() or similar.
> 
> The only reliable way to find out exactly what is happening is to
> examine the program state at the point that the segfault occurs;
> primarily, the arguments which are passed to strcmp().

Following fix cures the problem for env.c:
cvs diff -u env.c
RCS file: /grassrepository/grass/src/libes/gis/env.c,v
retrieving revision 1.5
diff -u -r1.5 env.c
--- env.c       12 May 2002 12:04:45 -0000      1.5
+++ env.c       23 May 2002 08:25:33 -0000
@@ -177,13 +177,12 @@
     int n;
 
     for (n = 0; n < count; n++)
-       if (env[n].name && (strcmp(env[n].name, name)==0))
+       if (env[n].name && (strlen(name)!=0) && (strcmp(env[n].name, name)==0))
        {
            free (env[n].name);
            env[n].name = 0;
            return 1;
        }
-
     return 0;
 }

Objections to submit this fix?

But...
Then the next bug occurs due to the new NAD datum support:
In r.proj/main.c line 279 is the function G_database_datum_name() used:
   strncpy(in_datum,G_database_datum_name(),sizeof(in_datum));
For my existing locations it returns NULL which causes a crash
of strncpy(). The function G_database_datum_name() is in
src/libes/gis/proj3.c

How to solve that one (hi Roger)? Therefore [vs].proj are also affected.

 Markus




More information about the grass-dev mailing list