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

[xen staging-4.10] tools/misc: fix hypothetical buffer overflow in xen-lowmemd



commit 6e636f297f12a52ce12db11ea0787dd541937ed6
Author:     Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
AuthorDate: Thu Apr 5 03:50:50 2018 +0200
Commit:     Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
CommitDate: Wed Jun 10 11:52:02 2020 +0100

    tools/misc: fix hypothetical buffer overflow in xen-lowmemd
    
    gcc-8 complains:
    
        xen-lowmemd.c: In function 'handle_low_mem':
        xen-lowmemd.c:80:55: error: '%s' directive output may be truncated 
writing up to 511 bytes into a region of size 489 [-Werror=format-truncation=]
                 snprintf(error, BUFSZ,"Failed to write target %s to xenstore", 
data);
                                                               ^~               
~~~~
        xen-lowmemd.c:80:9: note: 'snprintf' output between 36 and 547 bytes 
into a destination of size 512
                 snprintf(error, BUFSZ,"Failed to write target %s to xenstore", 
data);
                 
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    In practice it wouldn't happen, because 'data' contains string
    representation of 64-bit unsigned number (20 characters at most).
    But place a limit to mute gcc warning.
    
    Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
    Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Release-Acked-by: Juergen Gross <jgross@xxxxxxxx>
    (cherry picked from commit 27751d89248c8c5eef6d8b56eb8f7d2084145080)
---
 tools/misc/xen-lowmemd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/misc/xen-lowmemd.c b/tools/misc/xen-lowmemd.c
index 865a54cec1..79ad34cb4a 100644
--- a/tools/misc/xen-lowmemd.c
+++ b/tools/misc/xen-lowmemd.c
@@ -77,7 +77,7 @@ void handle_low_mem(void)
     if (!xs_write(xs_handle, XBT_NULL, 
             "/local/domain/0/memory/target", data, strlen(data)))
     {
-        snprintf(error, BUFSZ,"Failed to write target %s to xenstore", data);
+        snprintf(error, BUFSZ,"Failed to write target %.24s to xenstore", 
data);
         perror(error);
     }
 }
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10



 


Rackspace

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