public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] ASoC: soc: snprintf() doesn't return negative
@ 2010-10-11  3:54 Dan Carpenter
  2010-10-11 10:07 ` Liam Girdwood
  2010-10-11 10:40 ` Mark Brown
  0 siblings, 2 replies; 12+ messages in thread
From: Dan Carpenter @ 2010-10-11  3:54 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: alsa-devel, Jassi Brar, Takashi Iwai, kernel-janitors, Mark Brown,
	Peter Ujfalusi

In user space snprintf() returns negative on errors but the kernel
version only returns positives.  It could potentially return sizes
larger than the size of the buffer so we should check for that.

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

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 8751efd..8da307b 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -284,8 +284,10 @@ static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
 		ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
 				codec->name);
 
-	if (ret >= 0)
-		ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+	if (ret > PAGE_SIZE)
+		ret = PAGE_SIZE;
+
+	ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
 
 	kfree(buf);
 
@@ -310,8 +312,10 @@ static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
 	list_for_each_entry(dai, &dai_list, list)
 		ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
 
-	if (ret >= 0)
-		ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+	if (ret > PAGE_SIZE)
+		ret = PAGE_SIZE;
+
+	ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
 
 	kfree(buf);
 
@@ -338,8 +342,10 @@ static ssize_t platform_list_read_file(struct file *file,
 		ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
 				platform->name);
 
-	if (ret >= 0)
-		ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+	if (ret > PAGE_SIZE)
+		ret = PAGE_SIZE;
+
+	ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
 
 	kfree(buf);
 

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

end of thread, other threads:[~2010-10-12 10:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-11  3:54 [patch] ASoC: soc: snprintf() doesn't return negative Dan Carpenter
2010-10-11 10:07 ` Liam Girdwood
2010-10-11 10:40 ` Mark Brown
2010-10-11 16:40   ` Dan Carpenter
2010-10-11 18:51     ` Mark Brown
2010-10-11 19:45       ` Dan Carpenter
2010-10-11 20:57         ` Takashi Iwai
2010-10-12  9:35           ` Mark Brown
2010-10-12  9:49             ` Takashi Iwai
2010-10-12  9:56               ` Mark Brown
2010-10-12 10:40                 ` Dan Carpenter
2010-10-11 21:11         ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox