Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumpuser Terminate result of readlink(). Makes write...



details:   https://anonhg.NetBSD.org/src/rev/6c5fd6b03289
branches:  trunk
changeset: 785540:6c5fd6b03289
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Mar 18 21:00:52 2013 +0000

description:
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!

diffstat:

 lib/librumpuser/rumpuser.c |  9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diffs (37 lines):

diff -r 8ff592c70f47 -r 6c5fd6b03289 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Mon Mar 18 20:03:56 2013 +0000
+++ b/lib/librumpuser/rumpuser.c        Mon Mar 18 21:00:52 2013 +0000
@@ -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 @@
 
        /* 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 @@
                return -1;
        }
 
+       linkbuf[nn] = '\0';
        if (inotify_add_watch(inotify, linkbuf, IN_MODIFY) == -1) {
                seterror(errno);
                close(inotify);



Home | Main Index | Thread Index | Old Index