From: "Magnus Vigerlöf" <wigge@bigfoot.com>
To: linux-input@atrey.karlin.mff.cuni.cz
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] input: Null-termination of strings returned to userspace
Date: Wed, 2 Aug 2006 23:36:30 +0200 [thread overview]
Message-ID: <200608022336.30648.wigge@bigfoot.com> (raw)
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,
reply other threads:[~2006-08-02 21:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=200608022336.30648.wigge@bigfoot.com \
--to=wigge@bigfoot.com \
--cc=linux-input@atrey.karlin.mff.cuni.cz \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®