Lost last character in messages(init.c)

walter harms wharms at bfs.de
Wed Dec 10 09:10:36 UTC 2008



Aleksei Makhaloff schrieb:
> Trouble: lost the lastest character in messages(init.c)
> Log example:
> Low memory, forcing swapo
> cannot run 'mount': Invalid argumen
> The system is going down NOW
> Sending SIGTERM to all processe
> Sending SIGKILL to all processe
> Requesting system hal
> 
> 
> Please apply this patch.
> 
> diff -urN busybox-1.13.0.old/init/init.c busybox-1.13.0.new/init/init.c
> --- busybox-1.13.0.old/init/init.c      2008-12-09 20:30:31.000000000 +0300
> +++ busybox-1.13.0.new/init/init.c      2008-12-09 20:20:22.000000000 +0300
> @@ -118,7 +118,7 @@
> 
>        msg[0] = '\r';
>        va_start(arguments, fmt);
> -       l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
> +       l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments) + 1;


>        if (l > sizeof(msg) - 2)
>                l = sizeof(msg) - 2;
>        msg[l] = '\0';

can we replace it just with:  ?
   msg[sizeof(msg) - 2] = '\0';

if l>=(sizeof(msg) - 2) it will guarantee a terminating 0, else we set it twice what is harmless as snprintf
will terminate with 0.

re,
 wh











More information about the busybox mailing list