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

[Xen-changelog] [xen master] xl: NULL terminate buf when reading dom0 /proc/uptime



commit 8891dccfed78c6ee03b8912ed5353b83595a9549
Author:     Ian Campbell <ian.campbell@xxxxxxxxxx>
AuthorDate: Wed Feb 17 10:34:24 2016 +0000
Commit:     Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CommitDate: Tue Mar 1 16:11:10 2016 +0000

    xl: NULL terminate buf when reading dom0 /proc/uptime
    
    The contents of /proc/uptime is typically something like "80164.57
    640617.58", so the existing 512 byte buffer is more than large enoguh,
    so reduce its effective size to 511 bytes and ensure we include a
    NULL.
    
    Otherwise Coverity points out that we pass a potentially unterminated
    string to strtok. In practice this likely doesn't actually cause
    issues (at least on Linux) because the
    string should always contain a space so we will stop parsing.
    
    CID: 105590
    
    Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/xl_cmdimpl.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 4c03b2e..990d3c9 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -6963,6 +6963,7 @@ static char *current_time_to_string(time_t now)
 static void print_dom0_uptime(int short_mode, time_t now)
 {
     int fd;
+    ssize_t nr;
     char buf[512];
     uint32_t uptime = 0;
     char *uptime_str = NULL;
@@ -6973,12 +6974,15 @@ static void print_dom0_uptime(int short_mode, time_t 
now)
     if (fd == -1)
         goto err;
 
-    if (read(fd, buf, sizeof(buf)) == -1) {
+    nr = read(fd, buf, sizeof(buf) - 1);
+    if (nr == -1) {
         close(fd);
         goto err;
     }
     close(fd);
 
+    buf[nr] = '\0';
+
     strtok(buf, " ");
     uptime = strtoul(buf, NULL, 10);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.