Commit 2511cd0b3b9e9b1c3e9360cc565c3745ac3f3f3f

Authored by Martin Stava
Committed by Eric Van Hensbergen
1 parent f91b90993f

9p: fix readlink

I do not know if you've looked on the patch, but unfortunately it is
incorrect. A suggested better version is in this email (the old
version didn't work in case the user provided buffer was not long
enough - it incorrectly appended null byte on a position of last char,
and thus broke the contract of the readlink method). However, I'm
still not sure this is 100% correct thing to do, I think readlink is
supposed to return buffer without last null byte in all cases, but we
do return last null byte (even the old version).. on the other hand it
is likely unspecified what is in the remaining part of the buffer, so
null character may be fine there ;):

Signed-off-by: Martin Stava <martin.stava@gmail.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>

Showing 1 changed file with 2 additions and 3 deletions Side-by-side Diff

... ... @@ -994,8 +994,7 @@
994 994 P9_DPRINTK(P9_DEBUG_VFS,
995 995 "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer);
996 996  
997   - retval = buflen;
998   -
  997 + retval = strnlen(buffer, buflen);
999 998 done:
1000 999 kfree(st);
1001 1000 return retval;
... ... @@ -1062,7 +1061,7 @@
1062 1061 __putname(link);
1063 1062 link = ERR_PTR(len);
1064 1063 } else
1065   - link[len] = 0;
  1064 + link[min(len, PATH_MAX-1)] = 0;
1066 1065 }
1067 1066 nd_set_link(nd, link);
1068 1067