Bug 485

Summary: ash debug output segmentation fault
Product: Busybox Reporter: Earl Chew <echew>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P3    
Version: 1.14.x   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Host: Target:
Build:
Attachments: Correct diagnostic output
Patch which was applied to git. Checks for NEOF.

Description Earl Chew 2009-07-23 07:17:05 UTC
Diagnostic output sometimes causes segmentation fault.
Comment 1 Earl Chew 2009-07-23 07:17:32 UTC
Created attachment 495 [details]
Correct diagnostic output
Comment 2 Denys Vlasenko 2009-07-23 19:41:30 UTC
# make
  CC      shell/ash.o
cc1: warnings being treated as errors
shell/ash.c:10163: error: 'isneof' defined but not used
make[1]: *** [shell/ash.o] Error 1
make: *** [shell] Error 2
Comment 3 Denys Vlasenko 2009-07-23 19:49:27 UTC
                for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
-                       shcmd(lp->n, fp);
+                       shtree(lp->n, 0, NULL, fp);

Can you give an example when this change improves output?
Or is it fixes a bug?


This change does not actually change anything, AFAIKS:

-               n = n->nif.ifpart;
-               if (n->nif.elsepart) {
-                       cmdtxt(n);
+               if (!n->nif.elsepart) {
+                       n = n->nif.ifpart;
+               } else {
+                       cmdtxt(n->nif.ifpart);
                        cmdputs("; else ");
                        n = n->nif.elsepart;
                }

Why do you need it?
Comment 4 Denys Vlasenko 2009-07-23 20:06:30 UTC
Created attachment 497 [details]
Patch which was applied to git. Checks for NEOF.

Basically, it adds

+       if (n == NODE_EOF) {
+               fputs("<EOF>", fp);
+               return;
+       }

to shtree(). The rest is just renaming of NEOF into NODE_EOF.

Other parts of your fix wait for your comments, Earl. :)
Comment 5 Earl Chew 2009-07-23 21:12:12 UTC
(In reply to comment #2)
> # make
>   CC      shell/ash.o
> cc1: warnings being treated as errors
> shell/ash.c:10163: error: 'isneof' defined but not used
> make[1]: *** [shell/ash.o] Error 1
> make: *** [shell] Error 2
> 

Oops ... need to wrap in DEBUG:

#ifdef DEBUG
static int isneof(union node *n)
{
        return n == NEOF;
}
#endif
Comment 6 Earl Chew 2009-07-23 21:14:04 UTC
(In reply to comment #3)

> This change does not actually change anything, AFAIKS:
> 
> -               n = n->nif.ifpart;
> -               if (n->nif.elsepart) {

I'm fairly certain this is a defect.

I think the code needs to consider n->nif.ifpart and n->nif.elsepart.

The code as written considers n->nif.ifpart and n->nif.ifpart->nif.elsepart.
Comment 7 Earl Chew 2009-07-23 21:15:18 UTC
(In reply to comment #3)
>                 for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
> -                       shcmd(lp->n, fp);
> +                       shtree(lp->n, 0, NULL, fp);
> 
> Can you give an example when this change improves output?
> Or is it fixes a bug?

Late night.  I believe the following code breaks the original:


   ls | { while read ; do echo $f ; done ; }


Comment 8 Denys Vlasenko 2009-07-23 22:53:38 UTC
(In reply to comment #6)
> (In reply to comment #3)
> > This change does not actually change anything, AFAIKS:
> > -               n = n->nif.ifpart;
> > -               if (n->nif.elsepart) {
> 
> I'm fairly certain this is a defect.
> 
> I think the code needs to consider n->nif.ifpart and n->nif.elsepart.
> 
> The code as written considers n->nif.ifpart and n->nif.ifpart->nif.elsepart.

*blush*

I see now. fixing...
Comment 9 Denys Vlasenko 2009-07-23 23:08:51 UTC
(In reply to comment #7)
> >                 for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
> > -                       shcmd(lp->n, fp);
> > +                       shtree(lp->n, 0, NULL, fp);
> > 
> > Can you give an example when this change improves output?
> > Or is it fixes a bug?
> 
> Late night.  I believe the following code breaks the original:
> 
>    ls | { while read ; do echo $f ; done ; }

Can't reproduce. But I tend to believe you. Applying it too.

Thanks!
Comment 10 Denys Vlasenko 2009-07-25 09:16:26 UTC
Closing as fixed. If you can, please try current git and reopen if there are problems.