From c8b4c76eed87a28addbdc90f84635dd414796b51 Mon Sep 17 00:00:00 2001 From: kib Date: Fri, 20 Mar 2009 11:08:57 +0000 Subject: [PATCH] Do not underflow the buffer and then report the problem. Check for the condition before the buffer write. Also, since buflen is unsigned, previous check was ignored. Reviewed by: marcus Tested by: pho --- sys/kern/vfs_cache.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index f114c187bde6..0d506bc8e68e 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -970,13 +970,13 @@ vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir, if (error) return (error); } - *--bp = '/'; - buflen--; - if (buflen < 0) { + if (buflen <= 0) { numfullpathfail4++; CACHE_RUNLOCK(); return (ENOMEM); } + *--bp = '/'; + buflen--; slash_prefixed = 1; } while (vp != rdir && vp != rootvnode) { @@ -1013,14 +1013,14 @@ vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir, if (error) break; } - *--bp = '/'; - buflen--; - if (buflen < 0) { + if (buflen <= 0) { numfullpathfail4++; CACHE_RUNLOCK(); error = ENOMEM; break; } + *--bp = '/'; + buflen--; slash_prefixed = 1; } if (error)