mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] input: Null-termination of strings returned to userspace
@ 2006-08-02 21:36 Magnus Vigerlöf
  0 siblings, 0 replies; only message in thread
From: Magnus Vigerlöf @ 2006-08-02 21:36 UTC (permalink / raw)
  To: linux-input; +Cc: linux-kernel

Removes the risk of returning non-null terminated strings
to userspace in those cases the provided buffer is too small.

Signed-off-by: Magnus Vigerlöf <wigge@bigfoot.com>
---
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 12c7ab8..667333c 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -377,11 +377,13 @@ static int str_to_user(const char *str, 
 	if (!str)
 		return -ENOENT;
 
-	len = strlen(str) + 1;
-	if (len > maxlen)
-		len = maxlen;
+	len = strlen(str);
+	if (len >= maxlen)
+		len = maxlen - 1;
 
-	return copy_to_user(p, str, len) ? -EFAULT : len;
+	if (copy_to_user(p, str, len))
+		return -EFAULT;
+	return put_user('\0', (char __user *)p + len) ? -EFAULT : len + 1;
 }
 
 static long evdev_ioctl_handler(struct file *file, unsigned int cmd,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-08-02 21:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-02 21:36 [PATCH] input: Null-termination of strings returned to userspace Magnus Vigerlöf

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

all inboxes | Powered by JetHome®