[Toybox] vmstat bug + patch
José Bollo
jobol at nonadev.net
Wed Sep 2 01:36:08 PDT 2015
Hi Rob,
hey I was deeply asleep and ... ding... you're pinging me!
I hope that you are well, the health, the life, etc... Do you plan to
come in europe soon?
I'm not sure to really understand the reason why this mail has flawn to
my box. Is it because the patch of Colin Cross looks like mine? That is
a debate: in how many ways can a problem be fixed? Colin made the same
job as me (but he missed to use the const keyword).
I'm not really focused on putting my name anywhere. Having a version of
toybox that isn't buggy for that vintage command 'vm' is a need.
Best wishes
Jose Bollo
Le mardi 01 septembre 2015 à 14:44 -0700, enh a écrit :
> ping.
>
> here's yet another patch from the third person to hit this
> (https://android-review.googlesource.com/#/c/169242/):
>
> Author: Colin Cross <ccross at android.com>
> Date: Tue Sep 1 14:32:59 2015 -0700
>
> vmstat: reset header pointer when looping
>
> Modifying the headers pointer when printing the headers causes
> a buffer overrun the second time they are printed. Use a local
> header pointer that is reset to the beginning of the buffer for
> each loop.
>
> Change-Id: Id2520b78255833197b4075f789766395bc36f218
>
> diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
> index 9a38e45..5b79702 100644
> --- a/toys/other/vmstat.c
> +++ b/toys/other/vmstat.c
> @@ -96,14 +96,14 @@ void vmstat_main(void)
>
> // Print headers
> if (rows>3 && !(loop % (rows-3))) {
> + const char *header = headers;
> if (isatty(1)) terminal_size(0, &rows);
> else rows = 0;
>
> printf("procs -----------memory---------- ---swap-- -----io----
> -system-- ----cpu----\n");
> -
> for (i=0; i<sizeof(lengths); i++) {
> - printf(" %*s"+!i, lengths[i], headers);
> - headers += strlen(headers)+1;
> + printf(" %*s"+!i, lengths[i], header);
> + header += strlen(header)+1;
> }
> xputc('\n');
> }
>
>
> On Mon, May 11, 2015 at 1:22 AM, José Bollo <jobol at nonadev.net> wrote:
> > Please find here an alternate proposal for fixing that issue.
> > Best regards
> > José
> >
> >
> > diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
> > index eed7945..0884fe9 100644
> > --- a/toys/other/vmstat.c
> > +++ b/toys/other/vmstat.c
> > @@ -93,14 +93,15 @@ void vmstat_main(void)
> >
> > // Print headers
> > if (rows>3 && !(loop % (rows-3))) {
> > + char *h = headers;
> > if (isatty(1)) terminal_size(0, &rows);
> > else rows = 0;
> >
> > printf("procs -----------memory---------- ---swap-- -----io----
> > -system-- ----cpu----\n");
> >
> > for (i=0; i<sizeof(lengths); i++) {
> > - printf(" %*s"+!i, lengths[i], headers);
> > - headers += strlen(headers)+1;
> > + printf(" %*s"+!i, lengths[i], h++);
> > + while(*h++ != 0);
> > }
> > xputc('\n');
> > }
> >
> >
> >
> > _______________________________________________
> > Toybox mailing list
> > Toybox at lists.landley.net
> > http://lists.landley.net/listinfo.cgi/toybox-landley.net
>
>
>
1441182968.0
More information about the Toybox
mailing list