]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fortify: check the value returned from write(2)
authorDwight Engen <dwight.engen@oracle.com>
Mon, 15 Apr 2013 19:40:53 +0000 (15:40 -0400)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 16 Apr 2013 10:15:29 +0000 (12:15 +0200)
Also check that we wrote the amount we expected to. The write on the pty
is blocking but we could still get a short write on EINTR, so we should
SYSERROR it.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc_console.c

index 3dd2155c620bb01327cd4358f7164aff66be9858..643c442767c14c20a7828407bb348fcf062e073c 100644 (file)
@@ -165,14 +165,18 @@ static int master_handler(int fd, void *data, struct lxc_epoll_descr *descr)
 {
        char buf[1024];
        int *peer = (int *)data;
-       int r;
+       int r,w;
 
        r = read(fd, buf, sizeof(buf));
        if (r < 0) {
                SYSERROR("failed to read");
                return 1;
        }
-       r = write(*peer, buf, r);
+       w = write(*peer, buf, r);
+       if (w < 0 || w != r) {
+               SYSERROR("failed to write");
+               return 1;
+       }
 
        return 0;
 }