Skip to content

Commit

Permalink
9p: fix readlink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Martin Stava authored and Eric Van Hensbergen committed Nov 2, 2009
1 parent f91b909 commit 2511cd0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions fs/9p/vfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
P9_DPRINTK(P9_DEBUG_VFS,
"%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer);

retval = buflen;

retval = strnlen(buffer, buflen);
done:
kfree(st);
return retval;
Expand Down Expand Up @@ -1062,7 +1061,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
__putname(link);
link = ERR_PTR(len);
} else
link[len] = 0;
link[min(len, PATH_MAX-1)] = 0;
}
nd_set_link(nd, link);

Expand Down

0 comments on commit 2511cd0

Please sign in to comment.