Re: [PATCH] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_cstr()
flat view
From: Kees Cook <hidden>
Date: 2023-10-26 17:54:31
Also in:
linux-hardening, lkml
On Thu, Oct 26, 2023 at 01:38:50PM -0400, Steven Rostedt wrote:
On Thu, 26 Oct 2023 10:07:28 -0700 Kees Cook [off-list ref] wrote:quoted
Solve two ergonomic issues with struct seq_buf:"ergonomic"? Does it cause carpal tunnel? ;-)quoted
1) Too much boilerplate is required to initialize: struct seq_buf s; char buf[32]; seq_buf_init(s, buf, sizeof(buf)); Instead, we can build this directly on the stack. Provide DECLARE_SEQ_BUF() macro to do this: DECLARE_SEQ_BUF(s, 32); 2) %NUL termination is fragile and requires 2 steps to get a valid C String (and is a layering violation exposing the "internals" of seq_buf): seq_buf_terminate(s); do_something(s->buffer); Instead, we can just return s->buffer direction after terminating it in refactored seq_buf_terminate(), now known as seq_buf_cstr(): do_soemthing(seq_buf_cstr(s));Do we really need to call it _cstr? Why not just have seq_buf_str() ? I mean, this is C, do we need to state that in the name too?
I'm fine either way. I did that just to make the distinction between our length-managed string of characters interface (seq_buf), and the %NUL-terminated string of characters (traditionally called "C String" in other languages). And it was still shorter than "seq_buf_terminate(s); s->buffer" ;)
BTW, I'm perfectly fine with this change, just the naming I have issues with.
Cool; thanks for looking at it! -- Kees Cook