diff options
author | Jan Kara <jack@suse.cz> | 2015-06-03 09:50:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-03 11:00:22 -0400 |
commit | 226a07ef0a5a2dfad4cce1a5c226c4cb7370d41f (patch) | |
tree | 7b957c610ea1df9e099173ac29e84ef7ca6856b4 | |
parent | 8cd9234c64c584432f6992fe944ca9e46ca8ea76 (diff) |
lib: Clarify the return value of strnlen_user()
strnlen_user() can return a number in a range 0 to count +
sizeof(unsigned long) - 1. Clarify the comment at the top of the
function so that users don't think the function returns at most count+1.
Signed-off-by: Jan Kara <jack@suse.cz>
[ Also added commentary about preferably not using this function ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | lib/strnlen_user.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c index 11649615c505..fe9a32591c24 100644 --- a/lib/strnlen_user.c +++ b/lib/strnlen_user.c | |||
@@ -90,8 +90,15 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count, | |||
90 | * Get the size of a NUL-terminated string in user space. | 90 | * Get the size of a NUL-terminated string in user space. |
91 | * | 91 | * |
92 | * Returns the size of the string INCLUDING the terminating NUL. | 92 | * Returns the size of the string INCLUDING the terminating NUL. |
93 | * If the string is too long, returns 'count+1'. | 93 | * If the string is too long, returns a number larger than @count. User |
94 | * has to check the return value against "> count". | ||
94 | * On exception (or invalid count), returns 0. | 95 | * On exception (or invalid count), returns 0. |
96 | * | ||
97 | * NOTE! You should basically never use this function. There is | ||
98 | * almost never any valid case for using the length of a user space | ||
99 | * string, since the string can be changed at any time by other | ||
100 | * threads. Use "strncpy_from_user()" instead to get a stable copy | ||
101 | * of the string. | ||
95 | */ | 102 | */ |
96 | long strnlen_user(const char __user *str, long count) | 103 | long strnlen_user(const char __user *str, long count) |
97 | { | 104 | { |