Skip to content

Commit

Permalink
fs/9p: avoid debug OOPS when reading a long symlink
Browse files Browse the repository at this point in the history
Reading a symlink longer than the given buffer, a p9_debug use would
try to print the link name (not NUL-terminated) using a %s format.
Use %.*s instead, and replace the strncpy+strnlen with functionally
equivalent strlen+memcpy.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
  • Loading branch information
Jim Meyering authored and Eric Van Hensbergen committed Sep 6, 2012
1 parent 4cbe5a5 commit ba413ab
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fs/9p/vfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,12 +1276,12 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
}

/* copy extension buffer into buffer */
strncpy(buffer, st->extension, buflen);
retval = min(strlen(st->extension)+1, (size_t)buflen);
memcpy(buffer, st->extension, retval);

p9_debug(P9_DEBUG_VFS, "%s -> %s (%s)\n",
dentry->d_name.name, st->extension, buffer);
p9_debug(P9_DEBUG_VFS, "%s -> %s (%.*s)\n",
dentry->d_name.name, st->extension, buflen, buffer);

retval = strnlen(buffer, buflen);
done:
p9stat_free(st);
kfree(st);
Expand Down

0 comments on commit ba413ab

Please sign in to comment.