Module Name:    src
Committed By:   manu
Date:           Tue Sep 30 00:06:19 UTC 2014

Modified Files:
        src/lib/libperfuse: ops.c

Log Message:
Do not trust the filesystem's readdir to give us nul-terminated file names


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/lib/libperfuse/ops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.74 src/lib/libperfuse/ops.c:1.75
--- src/lib/libperfuse/ops.c:1.74	Thu Sep 11 04:05:52 2014
+++ src/lib/libperfuse/ops.c	Tue Sep 30 00:06:19 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.74 2014/09/11 04:05:52 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.75 2014/09/30 00:06:19 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -607,6 +607,7 @@ fuse_to_dirent(struct puffs_usermount *p
 	do {
 		char *ndp;
 		size_t reclen;
+		char name[MAXPATHLEN];
 
 		reclen = _DIRENT_RECLEN(dents, fd->namelen);
 
@@ -639,6 +640,9 @@ fuse_to_dirent(struct puffs_usermount *p
 			dents = (struct dirent *)(void *)ndp;
 		}
 		
+		strncpy(name, fd->name, fd->namelen);
+		name[fd->namelen] = '\0';
+
 		/*
 		 * Filesystem was mounted without -o use_ino
 		 * Perform a lookup to find it.
@@ -651,13 +655,17 @@ fuse_to_dirent(struct puffs_usermount *p
 			 * Avoid breaking out of fs 
 			 * by lookup to .. on root
 			 */
-			if ((strcmp(fd->name, "..") == 0) && 
+			if ((strcmp(name, "..") == 0) && 
 			    (pnd->pnd_nodeid == FUSE_ROOT_ID)) {
 				fd->ino = FUSE_ROOT_ID;
 			} else {
-				if (node_lookup_common(pu, opc, NULL, fd->name,
-						       NULL, &pn) != 0) {
-					DWARNX("node_lookup_common failed");
+				int error;
+
+				error = node_lookup_common(pu, opc, NULL, 
+							   name, NULL, &pn);
+				if (error != 0) {
+					DWARNX("node_lookup_common %s "
+					       "failed: %d", name, error);
 				} else {
 					fd->ino = pn->pn_va.va_fileid;
 					(void)perfuse_node_reclaim(pu, pn);
@@ -669,7 +677,7 @@ fuse_to_dirent(struct puffs_usermount *p
 		dents->d_reclen = (unsigned short)reclen;
 		dents->d_namlen = fd->namelen;
 		dents->d_type = fd->type;
-		strlcpy(dents->d_name, fd->name, fd->namelen + 1);
+		strlcpy(dents->d_name, name, fd->namelen + 1);
 
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags & PDF_READDIR)
@@ -720,7 +728,7 @@ fuse_to_dirent(struct puffs_usermount *p
 	 */
 	if (written != -1)
 		PERFUSE_NODE_DATA(opc)->pnd_dirent_len = written;
-	
+
 	return written;
 }
 

Reply via email to