Skip to contentSkip to conversation

caif: handle snprintf() return

PATCH Applied Dan Carpenter 2 participants 2 messages Jul 26, 2010 – Jul 27, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 caif: handle snprintf() return

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.

drivers/net/caif/caif_spi.c +3 -0
index 6c94803..f5058ff 100644
@@ -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);
 
maintainer Applied
#1 lore raw

From: Dan Carpenter <[email protected]>
Date: Mon, 26 Jul 2010 09:23:59 +0200

Quoted 6 lines

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.

Applied.