Module Name: src
Committed By: rmind
Date: Thu Oct 31 00:59:17 UTC 2013
Modified Files:
src/sys/fs/tmpfs: tmpfs_subr.c tmpfs_vnops.c
Log Message:
tmpfs_alloc_node: it is less error-prone to store the link path with
the NIL terminator included. Adjust tmpfs_readlink() to exclude NIL.
Also, remove the check for zero-length and add some asserts.
To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/fs/tmpfs/tmpfs_subr.c
cvs rdiff -u -r1.103 -r1.104 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.80 src/sys/fs/tmpfs/tmpfs_subr.c:1.81
--- src/sys/fs/tmpfs/tmpfs_subr.c:1.80 Fri Oct 4 15:14:11 2013
+++ src/sys/fs/tmpfs/tmpfs_subr.c Thu Oct 31 00:59:17 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_subr.c,v 1.80 2013/10/04 15:14:11 rmind Exp $ */
+/* $NetBSD: tmpfs_subr.c,v 1.81 2013/10/31 00:59:17 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.80 2013/10/04 15:14:11 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.81 2013/10/31 00:59:17 rmind Exp $");
#include <sys/param.h>
#include <sys/dirent.h>
@@ -166,13 +166,13 @@ tmpfs_alloc_node(tmpfs_mount_t *tmp, enu
break;
case VLNK:
/* Symbolic link. Target specifies the file name. */
- KASSERT(target && strlen(target) < MAXPATHLEN);
+ KASSERT(target != NULL);
nnode->tn_size = strlen(target);
- if (nnode->tn_size == 0) {
- nnode->tn_spec.tn_lnk.tn_link = NULL;
- break;
- }
+ KASSERT(nnode->tn_size > 0);
+ KASSERT(nnode->tn_size < MAXPATHLEN);
+ nnode->tn_size++; /* include the NIL */
+
nnode->tn_spec.tn_lnk.tn_link =
tmpfs_strname_alloc(tmp, nnode->tn_size);
if (nnode->tn_spec.tn_lnk.tn_link == NULL) {
Index: src/sys/fs/tmpfs/tmpfs_vnops.c
diff -u src/sys/fs/tmpfs/tmpfs_vnops.c:1.103 src/sys/fs/tmpfs/tmpfs_vnops.c:1.104
--- src/sys/fs/tmpfs/tmpfs_vnops.c:1.103 Fri Oct 4 15:14:11 2013
+++ src/sys/fs/tmpfs/tmpfs_vnops.c Thu Oct 31 00:59:17 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_vnops.c,v 1.103 2013/10/04 15:14:11 rmind Exp $ */
+/* $NetBSD: tmpfs_vnops.c,v 1.104 2013/10/31 00:59:17 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.103 2013/10/04 15:14:11 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.104 2013/10/31 00:59:17 rmind Exp $");
#include <sys/param.h>
#include <sys/dirent.h>
@@ -1030,16 +1030,17 @@ tmpfs_readlink(void *v)
} */ *ap = v;
vnode_t *vp = ap->a_vp;
struct uio *uio = ap->a_uio;
- tmpfs_node_t *node;
+ tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp);
int error;
KASSERT(VOP_ISLOCKED(vp));
KASSERT(uio->uio_offset == 0);
KASSERT(vp->v_type == VLNK);
+ KASSERT(node->tn_size > 0);
- node = VP_TO_TMPFS_NODE(vp);
+ /* Note: readlink(2) returns the path without NIL. */
error = uiomove(node->tn_spec.tn_lnk.tn_link,
- MIN(node->tn_size, uio->uio_resid), uio);
+ MIN(node->tn_size - 1, uio->uio_resid), uio);
node->tn_status |= TMPFS_NODE_ACCESSED;
return error;