Module Name:    src
Committed By:   rmind
Date:           Fri Nov  1 15:38:45 UTC 2013

Modified Files:
        src/sys/fs/tmpfs: tmpfs_subr.c tmpfs_vnops.c

Log Message:
tmpfs: fix the zero-length symlink target case as NetBSD supports them.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/fs/tmpfs/tmpfs_subr.c
cvs rdiff -u -r1.104 -r1.105 src/sys/fs/tmpfs/tmpfs_vnops.c

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

Modified files:

Index: src/sys/fs/tmpfs/tmpfs_subr.c
diff -u src/sys/fs/tmpfs/tmpfs_subr.c:1.81 src/sys/fs/tmpfs/tmpfs_subr.c:1.82
--- src/sys/fs/tmpfs/tmpfs_subr.c:1.81	Thu Oct 31 00:59:17 2013
+++ src/sys/fs/tmpfs/tmpfs_subr.c	Fri Nov  1 15:38:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_subr.c,v 1.81 2013/10/31 00:59:17 rmind Exp $	*/
+/*	$NetBSD: tmpfs_subr.c,v 1.82 2013/11/01 15:38:45 rmind Exp $	*/
 
 /*
  * Copyright (c) 2005-2011 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.81 2013/10/31 00:59:17 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.82 2013/11/01 15:38:45 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/dirent.h>
@@ -167,11 +167,16 @@ tmpfs_alloc_node(tmpfs_mount_t *tmp, enu
 	case VLNK:
 		/* Symbolic link.  Target specifies the file name. */
 		KASSERT(target != NULL);
-
 		nnode->tn_size = strlen(target);
-		KASSERT(nnode->tn_size > 0);
+
+		if (nnode->tn_size == 0) {
+			/* Zero-length targets are supported. */
+			nnode->tn_spec.tn_lnk.tn_link = NULL;
+			break;
+		}
+
 		KASSERT(nnode->tn_size < MAXPATHLEN);
-		nnode->tn_size++; /* include the NIL */
+		nnode->tn_size++; /* include the NUL terminator */
 
 		nnode->tn_spec.tn_lnk.tn_link =
 		    tmpfs_strname_alloc(tmp, nnode->tn_size);

Index: src/sys/fs/tmpfs/tmpfs_vnops.c
diff -u src/sys/fs/tmpfs/tmpfs_vnops.c:1.104 src/sys/fs/tmpfs/tmpfs_vnops.c:1.105
--- src/sys/fs/tmpfs/tmpfs_vnops.c:1.104	Thu Oct 31 00:59:17 2013
+++ src/sys/fs/tmpfs/tmpfs_vnops.c	Fri Nov  1 15:38:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_vnops.c,v 1.104 2013/10/31 00:59:17 rmind Exp $	*/
+/*	$NetBSD: tmpfs_vnops.c,v 1.105 2013/11/01 15:38:45 rmind Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.104 2013/10/31 00:59:17 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.105 2013/11/01 15:38:45 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/dirent.h>
@@ -1036,11 +1036,14 @@ tmpfs_readlink(void *v)
 	KASSERT(VOP_ISLOCKED(vp));
 	KASSERT(uio->uio_offset == 0);
 	KASSERT(vp->v_type == VLNK);
-	KASSERT(node->tn_size > 0);
 
-	/* Note: readlink(2) returns the path without NIL. */
-	error = uiomove(node->tn_spec.tn_lnk.tn_link,
-	    MIN(node->tn_size - 1, uio->uio_resid), uio);
+	/* Note: readlink(2) returns the path without NUL terminator. */
+	if (node->tn_size > 0) {
+		error = uiomove(node->tn_spec.tn_lnk.tn_link,
+		    MIN(node->tn_size - 1, uio->uio_resid), uio);
+	} else {
+		error = 0;
+	}
 	node->tn_status |= TMPFS_NODE_ACCESSED;
 
 	return error;

Reply via email to