[GRASS-dev] [grass-code I][509] v.mkgrid: segfault when "grid"
parameters missing
Martin Landa
landa.martin at gmail.com
Thu Oct 11 07:06:26 EDT 2007
Hi Hamish,
see my comments on GForge [1]. I see problem in check_multiple_opts()
fn... The attached patch is too simple, should be fixed in more robust
way...
Martin
[1] http://wald.intevation.org/tracker/?func=detail&atid=204&aid=509&group_id=21
2007/10/11, Hamish <hamish_nospam at yahoo.com>:
> > code I item #509, was opened at 2007-10-11 10:29
> > Summary: v.mkgrid: segfault when "grid" parameters missing
> ..
> > If the user fails to provide "grid" parameters, it segfaults. Applies to bot
> > 6.2 CVS and 6.3 CVS. Example:
> >
> > $ v.mkgrid map=debug_grid position=region grid=
> > Segmentation fault (core dumped)
> >
> > backtrace:
> >
> > Program received signal SIGSEGV, Segmentation fault.
> > [Switching to Thread 46912562415552 (LWP 26775)]
> > 0x00002aaaabe92cf1 in __strtoull_internal () from /lib/libc.so.6
> > (gdb) bt
> > #0 0x00002aaaabe92cf1 in __strtoull_internal () from /lib/libc.so.6
> > #1 0x00002aaaaba65022 in atoi () from /usr/local/lib/libgdal.so.1
> > #2 0x0000000000401a25 in main (argc=4, argv=0x7fffff972dd8) at main.c:142
>
> It is in the main.c atoi("") [line 137], but I'm not sure why it thinks that's
> found in libgdal.
>
> the root of the problem is that even though the option is declared
> TYPE_INTEGER, that is never checked.
> v.mkgrid/main.c has
> grid = G_define_option ();
> grid->key = "grid";
> grid->key_desc = "rows,columns";
> grid->type = TYPE_INTEGER;
> grid->required = YES;
> grid->multiple = NO;
> grid->description = _("Number of rows and columns in grid");
>
>
> in lib/gis/parser.c ~ line 2136 the check_opts() fn skips sending it to
> check_an_opt() as (opt->options && opt->answer) are (null) and "" respectively.
> [ie not allocated, and allocated but set to "\0" (?)]
>
> it would be easy to add to v.mkgrid a test for the answer being empty and throw
> it to {G_usage(); exit(EXIT_FAILURE);}, but that doesn't solve the general
> problem- the parser should check for an integer answer. (same for TYPE_DOUBLE,
> ...) Note in this case the checker has to check key_desc to know to expect two
> int answers.
>
> G_parser() does catch the "grid=1," error with a please supply two values
> message. so maybe the problem is in check_multiple_opts()?
>
>
>
> Interesting, I hadn't noticed the parser's custom opt->checker option-option
> before.
>
>
> Hamish
>
>
>
> ____________________________________________________________________________________
> Don't let your dream ride pass you by. Make it a reality with Yahoo! Autos.
> http://autos.yahoo.com/index.html
>
>
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass-dev
>
--
Martin Landa <landa.martin at gmail.com> * http://gama.fsv.cvut.cz/~landa *
More information about the grass-dev
mailing list