[PATCH] svlogd: Fix potential deref-of-null
David Laight
David.Laight at ACULAB.COM
Mon Oct 28 10:56:59 UTC 2024
From: Maks Mishin
> Sent: 17 September 2024 05:37
>
> Pointer, returned from function 'gmtime_r' at svlogd.c:355, may be NULL
> and is dereferenced at svlogd.c:358.
>
> Found by RASU JSC with SVACE.
>
> Signed-off-by: Maks Mishin <maks.mishinFZ at gmail.com>
> ---
> runit/svlogd.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/runit/svlogd.c b/runit/svlogd.c
> index f7576f0fa..ff7224a34 100644
> --- a/runit/svlogd.c
> +++ b/runit/svlogd.c
> @@ -353,6 +353,9 @@ static void fmt_time_human_30nul(char *s, char dt_delim)
>
> xgettimeofday(&tv);
> ptm = gmtime_r(&tv.tv_sec, &tm);
> +if (ptm == NULL)
> +return;
> +
It looks like you are returning without even terminating the output buffer.
That is likely to be worse than the SIGSEGV in the unlikely case that
gmtime_r() return NULL.
Without a sane error path the SIGSEGV isn't really that bad at all.
David
> /* ^^^ using gmtime_r() instead of gmtime() to not use static data */
> sprintf(s, "%04u-%02u-%02u%c%02u:%02u:%02u.%06u000",
> (unsigned)(1900 + ptm->tm_year),
> --
> 2.34.1
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
>
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
More information about the busybox
mailing list