Module Name: src Committed By: pooka Date: Mon Mar 18 21:00:52 UTC 2013
Modified Files: src/lib/librumpuser: rumpuser.c Log Message: Terminate result of readlink(). Makes writefilewatch_setup() work in cases when the buffer doesn't accidentally contain suitable zeroes. Thanks to Juan RP who debugged this with me! To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/lib/librumpuser/rumpuser.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/librumpuser/rumpuser.c diff -u src/lib/librumpuser/rumpuser.c:1.28 src/lib/librumpuser/rumpuser.c:1.29 --- src/lib/librumpuser/rumpuser.c:1.28 Mon Jan 14 21:04:15 2013 +++ src/lib/librumpuser/rumpuser.c Mon Mar 18 21:00:52 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.c,v 1.28 2013/01/14 21:04:15 pooka Exp $ */ +/* $NetBSD: rumpuser.c,v 1.29 2013/03/18 21:00:52 pooka Exp $ */ /* * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser.c,v 1.28 2013/01/14 21:04:15 pooka Exp $"); +__RCSID("$NetBSD: rumpuser.c,v 1.29 2013/03/18 21:00:52 pooka Exp $"); #endif /* !lint */ #include <sys/ioctl.h> @@ -660,8 +660,8 @@ rumpuser_writewatchfile_setup(int inotif /* ok, need to map fd into path for inotify */ snprintf(procbuf, sizeof(procbuf), "/proc/self/fd/%d", fd); - nn = readlink(procbuf, linkbuf, sizeof(linkbuf)); - if (nn >= (ssize_t)sizeof(linkbuf)) { + nn = readlink(procbuf, linkbuf, sizeof(linkbuf)-1); + if (nn >= (ssize_t)sizeof(linkbuf)-1) { nn = -1; errno = E2BIG; /* pick something */ } @@ -671,6 +671,7 @@ rumpuser_writewatchfile_setup(int inotif return -1; } + linkbuf[nn] = '\0'; if (inotify_add_watch(inotify, linkbuf, IN_MODIFY) == -1) { seterror(errno); close(inotify);