[Toybox] [groups] : ! More than one in group is error

Rob Landley rob at landley.net
Thu Dec 27 06:21:49 PST 2012


On 12/26/2012 10:24:53 PM, Ashwini Sharma wrote:
> Hey Rob,
> 
>  Options mutual exclusion handling is having a Seg Fault in function
> gotflag.

I think that means you referenced an option that doesn't exist. (If you  
enable TOYBOX_DEBUG in the config, it's supposed to catch this and spit  
out an "unknown target" message during parse_optflaglist().

What does your option string look like?

> The block handling this doesn't have a terminating condition, hence  
> once it
> goes beyond the options list, it crashes.

Because it should enver go beyond the options list because that means  
the option you referenced wasn't found. This is why the [groups] are  
supposed to go at the end of the options list.

  "abc[!ac]" shouldn't segfault.
  "abc[!ad]" won't find d and will fall off the list.

That said, I would have expected it to segfault on line 318  
dereferencing a null opt there, not in gotflag().

> At my end I have modified the code block from
> if (toys.optflags & gof->excludes) {
>     struct opts *bad;
>     unsigned i =
> 1;
> 
> 
>   *  for (bad=gof->opts; (gof->excludes && i; bad = bad->next) i<<=1;*
>     error_exit("No '%c' with '%c'", opt->c, bad->c);
>   }
> 
> to
> 
> if (toys.optflags & gof->excludes) {
>     struct opts *bad;
>     unsigned i =
> 1;
> 
> 
>    * gof->excludes &= ~opt->dex[1];
>     for (bad=gof->opts; bad && !(gof->excludes & i & toys.optflags) ;  
> bad =
> bad->next) i<<=1;*
>     error_exit("No '%c' with '%c'", opt->c, bad->c);
>   }
> 
> Please have a look and add the same to the mainline.

I'd like to understand how it got there. Could you show me the option  
string that triggered this behavior? I'd like to reproduce it so I  
understand what actually went wrong.

Also, does switching on TOYBOX_DEBUG catch whatever is wrong with the  
string? (If not, I need to add another test...)

Rob
 1356618109.0


More information about the Toybox mailing list