Skip to contentSkip to conversation

lib: Clarify the return value of strnlen_user()

PATCH In review Jan Kara 2 participants 2 messages Jun 3, 2015 Library code

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 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.

---
 lib/strnlen_user.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/strnlen_user.c +2 -1
index fd03ae980013..77bc67222b9d 100644
@@ -89,7 +89,8 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count,
  * Get the size of a NUL-terminated string in user space.
  *
  * Returns the size of the string INCLUDING the terminating NUL.
- * If the string is too long, returns 'count+1'.
+ * If the string is too long, returns a number larger than @count. User
+ * has to check the return value against "> count".
  * On exception (or invalid count), returns 0.
  */
 long strnlen_user(const char __user *str, long count)
Signature · 1 line
2.1.4
#1 lore raw
Quoted 3 lines · Jan Kara

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.

Thanks. I also extended the comment (in the same commit) on commentary on avoiding use of this function entirely.

Linus