netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] caif: handle snprintf() return
@ 2010-07-26  7:23 Dan Carpenter
  2010-07-27  4:05 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2010-07-26  7:23 UTC (permalink / raw)
  To: Sjur Braendeland; +Cc: David S. Miller, netdev, kernel-janitors

snprintf() returns the number of bytes that would have been written.  It
can be larger than the size of the buffer.  The current code won't
overflow, but people cut and paste this stuff so lets do it right and
also make the static checkers happy.

Signed-off-by: Dan Carpenter <error27@gmail.com>

diff --git a/drivers/net/caif/caif_spi.c b/drivers/net/caif/caif_spi.c
index 6c94803..f5058ff 100644
--- a/drivers/net/caif/caif_spi.c
+++ b/drivers/net/caif/caif_spi.c
@@ -165,6 +165,9 @@ static ssize_t dbgfs_state(struct file *file, char __user *user_buf,
 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len),
 			"Next RX len: %d\n", cfspi->rx_npck_len);
 
+	if (len > DEBUGFS_BUF_SIZE)
+		len = DEBUGFS_BUF_SIZE;
+
 	size = simple_read_from_buffer(user_buf, count, ppos, buf, len);
 	kfree(buf);
 

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

* Re: [patch] caif: handle snprintf() return
  2010-07-26  7:23 [patch] caif: handle snprintf() return Dan Carpenter
@ 2010-07-27  4:05 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2010-07-27  4:05 UTC (permalink / raw)
  To: error27; +Cc: sjur.brandeland, netdev, kernel-janitors

From: Dan Carpenter <error27@gmail.com>
Date: Mon, 26 Jul 2010 09:23:59 +0200

> snprintf() returns the number of bytes that would have been written.  It
> can be larger than the size of the buffer.  The current code won't
> overflow, but people cut and paste this stuff so lets do it right and
> also make the static checkers happy.
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>

Applied.

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

end of thread, other threads:[~2010-07-27  4:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-26  7:23 [patch] caif: handle snprintf() return Dan Carpenter
2010-07-27  4:05 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).