diff mbox

[V9fs-developer] fs/9p: avoid debug OOPS when reading a long symlink

Message ID 1345481724-30108-3-git-send-email-jim@meyering.net (mailing list archive)
State New, archived
Headers show

Commit Message

Jim Meyering Aug. 20, 2012, 4:55 p.m. UTC
From: Jim Meyering <meyering@redhat.com>

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>
 fs/9p/vfs_inode.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox


diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index cbf9dbb..16ed405 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -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, 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);