[GRASS-dev] [GRASS GIS] #2351: g.version segfaults when the build is not perfect

GRASS GIS trac at osgeo.org
Wed Jun 25 14:29:46 PDT 2014


#2351: g.version segfaults when the build is not perfect
----------------------------------------------------------+-----------------
 Reporter:  wenzeslaus                                    |       Owner:  grass-dev@…              
     Type:  defect                                        |      Status:  new                      
 Priority:  normal                                        |   Milestone:  7.0.0                    
Component:  Compiling                                     |     Version:  unspecified              
 Keywords:  GIS_H_VERSION, GIS_H_DATA, libgis, g.version  |    Platform:  Linux                    
      Cpu:  Unspecified                                   |  
----------------------------------------------------------+-----------------
 G7:g.version often fails, segfaults in particular, with some wrong builds.
 It seems that it is happening for one or more Ubuntu packages.

 Here are some outputs I collected from the users.

 {{{
 > g.version -rge
 version=7.0.svn
 date=2013
 revision=
 build_date=2013-12-11
 Segmentation fault (core dumped)
 }}}


 {{{
 > g.gisenv set=DEBUG=5
 bash: /usr/lib/grass70/etc/prompt.py: File o directory non esistente
 > g.version -rge
 D2/5: G_file_name(): path =
 /media/massarelli/sdb/Mappe/GRASS/Puglia_Landsat_nord/PERMANENT
 version=7.0.0svn
 date=2014
 revision=
 build_date=2014-06-24
 build_platform=x86_64-pc-linux-gnu
 Errore di segmentazione (core dump creato)
 bash: /usr/lib/grass70/etc/prompt.py: File o directory non esistente
 }}}

 It seems that the strings `GIS_H_VERSION` and `GIS_H_DATE` are broken. I
 think that g.version should handle this since it is often used in cases
 when something is somehow broken.

 == Solution ==

 I don't know how to reproduce it but I created a patch assuming that
 `G_tokenize` works well with any input and `strstr` is failing with NULL
 pointer. The new version wants the results from `G_tokenize` to be of
 length 2. If this is not fulfilled, it prints a message or empty values
 (with `-g`) and with `g.gisenv set=DEBUG=5`, it prints also the original
 strings. Perhaps the message can be replaced by waring which would be
 printed even with `-g`.

 Patch attached. Let me know if I should commit this. Since I cannot test
 this much I'm not sure if it really helps.

 == Alternative solution ==

 I don't know why `GIS_H_VERSION` and `GIS_H_DATE` are wrong in the first
 place but if the problem is really there, maybe they should be obtained in
 some less fragile way than as SVN $$ things. Anyway, parsing the variables
 is hard and even GRASS is not doing it right (there are spaces at the end
 of the output), so some simplification in format of variables might be
 helpful.


 == strstr function and NULL ==

 {{{
 #!c
 #include <stdio.h>
 #include <string.h>

 int main ()
 {
     char * a = NULL;
     a = "\0"; // comment to get segfault
     printf("a=\"%s\"\n", a); fflush(stdout);
     char* b = strstr(a, "X");
     printf("b=\"%s\"\n", b); fflush(stdout);
     printf("Done\n"); fflush(stdout);
     return 0;
 }
 }}}

 {{{
 gcc teststrstr.c -o teststrstr && ./teststrstr
 }}}

 With `a = "\0";`:
 {{{
 a=""
 b="(null)"
 Done
 }}}

 Without `a = "\0";`:
 {{{
 a="(null)"
 Segmentation fault (core dumped)
 }}}


 == See also ==

  * [http://lists.osgeo.org/pipermail/grass-user/2014-January/069703.html
 GRASS-user g.extension]
  * [http://lists.osgeo.org/pipermail/grass-user/2014-June/070478.html
 GRASS-user keyError: 'version' g.extension grass7 ubuntu 14.04]
  * r58437 wxGUI: workaround for gui toolboxes compilation (g.version -r
 crashes and menu is not generated)
  * and some older emails on mailing lists

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2351>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list