[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87y1qjdimw.fsf@jogness.linutronix.de>
Date: Tue, 03 Jan 2023 11:26:23 +0106
From: John Ogness <john.ogness@...utronix.de>
To: Petr Mladek <pmladek@...e.com>
Cc: Sergey Senozhatsky <senozhatsky@...omium.org>,
Steven Rostedt <rostedt@...dmis.org>,
Thomas Gleixner <tglx@...utronix.de>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH printk v3 6/6] printk: introduce
console_prepend_dropped() for dropped messages
On 2023-01-02, Petr Mladek <pmladek@...e.com> wrote:
>> +static void console_prepend_dropped(struct console_message *cmsg, unsigned long dropped)
>> +{
>> + struct console_buffers *cbufs = cmsg->cbufs;
>> + const size_t scratchbuf_sz = sizeof(cbufs->scratchbuf);
>> + const size_t outbuf_sz = sizeof(cbufs->outbuf);
>> + char *scratchbuf = &cbufs->scratchbuf[0];
>> + char *outbuf = &cbufs->outbuf[0];
>> + size_t len;
>> +
>> + len = snprintf(scratchbuf, scratchbuf_sz,
>> + "** %lu printk messages dropped **\n", dropped);
>> +
>> + /*
>> + * Make sure outbuf is sufficiently large before prepending. Space
>> + * for a terminator is also counted in case truncation occurs.
>> + */
>> + if (WARN_ON_ONCE(len + 1 >= outbuf_sz))
>> + return;
>
> Strictly speaking, this should be:
>
> if (WARN_ON_ONCE(len >= outbuf_sz))
> return;
>
> The trailing '\0' will fit into the buffer when len < outbuf_sz.
You are correct.
My concern was that if "@len = @outbuf_sz - 1", the entire message will
be truncated and you will only see the dropped messages text. I wanted
at least 1 character from the message to survive. ;-)
How about the commments:
/*
* Make sure outbuf is sufficiently large before prepending. Space
* for a terminator and at least 1 byte of the message is also
* checked in case truncation is needed.
*/
John
Powered by blists - more mailing lists