[GRASS-dev] g.mapsets -l crash (sometimes)
Huidae Cho
grass4u at gmail.com
Sun Apr 12 23:42:01 EDT 2009
Markus,
If, for some reason, Path is empty, nchoices should be 0 and you should
be fine. Also, PERMANENT and G_mapset can be intentionally removed from
search list.
I think Path buffer (4096 bytes) can be flooded because your mapset
names are long. If you used just the -l flag without any other flags or
options, the number of mapsets also matters. The mapset_name array can
contain up to 256 (GMAPSET_MAX) mapset names. In fact, GMAPSET_MAX is
not the maximum number of mapsets, but the maximum length of the mapset
name.
I think these buffers should be dynamically allocated.
Huidae
On Sun, Apr 12, 2009 at 09:28:17PM +0200, Markus Neteler wrote:
> Hi,
>
> when running g.mapsets -l on a Linux box, I get segfault:
>
> ...
> terra_lst1km20080610.LST_Night.84144 terra_lst1km20090105.LST_Day.82812
> aqua_lst1km20080827.LST_Night.85210 terra_lst1km20080709.LST_Day.84201
> terra_lst1km20080628.LST_Night.84180 aqua_lst1km20080630.LST_Night.85102
> terra_lst1km20080703.LST_Day.84189 terra_lst1km20080720.LST_Night.84222
> terra_lst1km20090108.LST_Day.82818 aqua_lst1km20080730.LST_Night.85159
> terra_lst1km20080718.LST_Night.84218 aqua_lst1km20080621.LST_Day.85085
> aqua_lst1km20090228.LST_Night.82801 aqua_lst1km20090219.LST_Night.82783
> terra_lst1km20090105.LST_Night.84656 aqua_lst1km20080829.LST_Day.83596
> aqua_lst1km20080830.LST_Night.85216 aqua_lst1km20090228
> segmentation violation
>
> It appears that 'Path' in main_cmd.c is empty.
>
> Consider the following patch:
>
> svn diff general/g.mapsets/
> Index: general/g.mapsets/main_cmd.c
> ===================================================================
> --- general/g.mapsets/main_cmd.c (revision 36680)
> +++ general/g.mapsets/main_cmd.c (working copy)
> @@ -184,7 +184,13 @@
> goto DISPLAY;
> }
>
> - /* note I'm assuming that mapsets cannot have ' 's in them */
> + /* preset Path if empty */
> + if(strlen(Path) == 0){
> + strcat(Path, "PERMANENT");
> + strcat(Path, " ");
> + strcat(Path, G_mapset());
> + }
> + /* note I'm assuming that mapset names cannot have ' 's in them */
> tokens = G_tokenize(Path, " ");
>
> which appears to cue the problem (crash in strcmp() below because
> tokens is empty.
>
> Objections?
>
> Markus
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
More information about the grass-dev
mailing list