[Toybox] [PATCH] segfault during option parsing

Rob Landley rob at landley.net
Fri Jul 10 12:24:04 PDT 2015


On 07/07/2015 07:11 AM, Sameer Pradhan wrote:
> Hi Rob and List,
>  
> I faced a situation where the group option parsing logic causes a
> Segfault.

Because you had an option group containing an option that didn't exist
without TOYBOX_DEBUG enabled.

> The scenario is as follows:
>  
> Like in compress.c:
> USE_COMPRESS(NEWTOY(compress, "zcd9lrg[-cd][!zgLr]",
> TOYFLAG_USR|TOYFLAG_BIN))
>  
> The  '__L__' option is not in the argument list where as in the
> option group has '__L__' option.

Yup.

> If CFG_TOYBOX_DEBUG is enabled the current implementation hits the
> error_exit()

Yes, extra runtime checks to detect something that you have to modify
the source code in order to get wrong. (I.E. only a developer can screw
this up, users can't.)

> otherwise it's trying to access opt->c which causes the
> segfault. 
>  
>  
> Please find the patch for the same.

Which makes it silently ignore this type of error so it would persist
and possibly ship. The existing behavior is to segfault to force you to
notice something's wrong.

You can make an argument that the debug check should always be forced on
to explain the error, but it's something that should never happen at
runtime. Silently ignoring the problem is not an improvement.

Tell you what, I'll move the existing comment about it to the start of
the file in lib/args.c so people notice it, and add a bit about it to
code.html.

Thanks,

Rob

 1436556244.0


More information about the Toybox mailing list