Skip to content

Commit d551afc

Browse files
committed
printk: Use scnprintf() to print the message about the dropped messages on a console
Use scnprintf() for printing the message about dropped messages on a console. It returns the really written length of the message. It prevents potential buffer overflow when the returned length is later used to copy the buffer content. Note that the previous code was safe because the scratch buffer was big enough and the message always fit in. But scnprintf() makes it more safe, definitely. Reported-by: coverity-bot <[email protected]> Addresses-Coverity-ID: 1530570 ("Memory - corruptions") Fixes: c4fcc61 ("printk: introduce console_prepend_dropped() for dropped messages") Link: https://lore.kernel.org/r/202301131544.D9E804CCD@keescook Reviewed-by: John Ogness <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b0975c4 commit d551afc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/printk/printk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2716,7 +2716,7 @@ static void console_prepend_dropped(struct printk_message *pmsg, unsigned long d
27162716
char *outbuf = &pbufs->outbuf[0];
27172717
size_t len;
27182718

2719-
len = snprintf(scratchbuf, scratchbuf_sz,
2719+
len = scnprintf(scratchbuf, scratchbuf_sz,
27202720
"** %lu printk messages dropped **\n", dropped);
27212721

27222722
/*

0 commit comments

Comments
 (0)