Re: [PATCH v2 5/9] seq_buf: Add seq_buf_strlen()
From: Greg KH
Date: Sat Sep 19 2026 - 03:40:45 EST
On Fri, Sep 18, 2026 at 05:27:03PM -0700, Kees Cook wrote:
> +/**
> + * seq_buf_strlen - get the length of the NUL-terminated C string in seq_buf
> + * @s: the seq_buf handle
> + *
> + * This makes sure that the buffer in @s is NUL-terminated, exactly as
> + * seq_buf_str() does, and returns the length of the resulting string
> + * without walking it. Unlike seq_buf_used(), this does not count the byte
> + * given up to the NUL when the buffer is full or has overflowed. When the
> + * buffer is exactly full, that byte is the last one written, and calling
> + * either function loses it.
> + *
> + * After this function is called, s->buffer is safe to use
> + * in string operations.
> + *
> + * Returns: the offset of the NUL that terminates @s->buffer. That is the
> + * length of the string unless an earlier NUL is in the way, either one the
> + * data written to @s carried itself, or one seq_buf_set_overflow() left
> + * behind when it cleared what no writer had claimed.
> + */
> +static inline size_t seq_buf_strlen(struct seq_buf *s)
> +{
> + if (WARN_ON(s->size == 0))
> + return 0;
Why WARN_ON()? Are you wanting to just mint new CVEs with this code
path, do we not give out enough already? :)
I can see returning 0, if it's empty, but isn't that a valid check for
people to wish to know at times? Why crash the box? (remember about
panic-on-warn being enabled in a few billion Linux instances...)
thanks,
greg k-h