From: Jules Maselbas <jmaselbas@kalray.eu>
To: barebox@lists.infradead.org
Cc: Neeraj Pal <neerajpal09@gmail.com>, Jules Maselbas <jmaselbas@kalray.eu>
Subject: [PATCH] common: console_common: Replace vsprintf with vsnprintf
Date: Sat, 17 Apr 2021 23:11:44 +0200 [thread overview]
Message-ID: <20210417211144.26466-1-jmaselbas@kalray.eu> (raw)
Replace the *sprintf to their *snprintf version when printing
to the fixed size printbuffer.
Reported-by: Neeraj Pal <neerajpal09@gmail.com>
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
common/console_common.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/common/console_common.c b/common/console_common.c
index 3e0741572..dc3a611e1 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -126,7 +126,7 @@ int pr_print(int level, const char *fmt, ...)
return 0;
va_start(args, fmt);
- i = vsprintf(printbuffer, fmt, args);
+ i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
va_end(args);
pr_puts(level, printbuffer);
@@ -139,18 +139,19 @@ int dev_printf(int level, const struct device_d *dev, const char *format, ...)
va_list args;
int ret = 0;
char printbuffer[CFG_PBSIZE];
+ size_t size = sizeof(printbuffer);
if (!IS_ENABLED(CONFIG_LOGBUF) && level > barebox_loglevel)
return 0;
if (dev->driver && dev->driver->name)
- ret += sprintf(printbuffer, "%s ", dev->driver->name);
+ ret += snprintf(printbuffer, size, "%s ", dev->driver->name);
- ret += sprintf(printbuffer + ret, "%s: ", dev_name(dev));
+ ret += snprintf(printbuffer + ret, size - ret, "%s: ", dev_name(dev));
va_start(args, format);
- ret += vsprintf(printbuffer + ret, format, args);
+ ret += vsnprintf(printbuffer + ret, size - ret, format, args);
va_end(args);
@@ -237,7 +238,7 @@ int printf(const char *fmt, ...)
* For this to work, printbuffer must be larger than
* anything we ever want to print.
*/
- i = vsprintf (printbuffer, fmt, args);
+ i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
va_end(args);
/* Print the string */
@@ -256,7 +257,7 @@ int vprintf(const char *fmt, va_list args)
* For this to work, printbuffer must be larger than
* anything we ever want to print.
*/
- i = vsprintf(printbuffer, fmt, args);
+ i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
/* Print the string */
puts(printbuffer);
@@ -344,7 +345,7 @@ int dprintf(int file, const char *fmt, ...)
* For this to work, printbuffer must be larger than
* anything we ever want to print.
*/
- vsprintf(printbuffer, fmt, args);
+ vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
va_end(args);
/* Print the string */
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2021-04-17 21:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-17 21:11 Jules Maselbas [this message]
2021-05-12 5:35 ` Sascha Hauer
2021-05-12 7:17 ` Jules Maselbas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210417211144.26466-1-jmaselbas@kalray.eu \
--to=jmaselbas@kalray.eu \
--cc=barebox@lists.infradead.org \
--cc=neerajpal09@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox