All of lore.kernel.org
 help / color / mirror / Atom feed
* seq_buf_putc() and strings
@ 2026-10-28 17:13 Alejandro Colomar
  2026-10-28 17:30 ` Alejandro Colomar
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Alejandro Colomar @ 2026-10-28 17:13 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Jiri Kosina, Petr Mladek, Kees Cook, linux-hardening

[-- Attachment #1: Type: text/plain, Size: 901 bytes --]

Hi Steven,


I've been looking at rewriting seq_buf with pointers instead of sizes.
While doing that, I've found one place which writes to seq_buf without
forming a proper string (that is, a null-terminated string).

	$ git show v7.3:lib/seq_buf.c | grepc seq_buf_putc
	(standard input):int seq_buf_putc(struct seq_buf *s, unsigned char c)
	{
		WARN_ON(s->size == 0);

		if (seq_buf_can_fit(s, 1)) {
			s->buffer[s->len++] = c;
			return 0;
		}
		seq_buf_set_overflow(s);
		return -1;
	}

I think a safe API for handling strings would have to make sure that it
*always* holds a string.  I think this function should write a NUL byte
after the byte written, and so, I suggest doing this:

	 		s->buffer[s->len++] = c;
	+		s->buffer[s->len] = '\0';

Are there any reasons to not write that NUL byte?


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-29  1:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 17:13 seq_buf_putc() and strings Alejandro Colomar
2026-10-28 17:30 ` Alejandro Colomar
2026-10-28 17:47 ` Steven Rostedt
2026-10-28 18:00   ` Alejandro Colomar
2026-10-28 20:59 ` seq_buf_used() return value on overflow Alejandro Colomar
2026-10-28 21:03   ` Alejandro Colomar
2026-10-28 21:30 ` seq_buf_str() silent truncation (data corruption) Alejandro Colomar
2026-10-29  1:04   ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.