WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] check read/write return values

To: xen-devel@xxxxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] check read/write return values
From: Rik van Riel <riel@xxxxxxxxxx>
Date: Sat, 19 Feb 2005 14:40:13 -0500 (EST)
Delivery-date: Sat, 19 Feb 2005 19:41:27 +0000
Envelope-to: xen+James.Bulpin@xxxxxxxxxxxx
List-archive: <http://sourceforge.net/mailarchive/forum.php?forum=xen-devel>
List-help: <mailto:xen-devel-request@lists.sourceforge.net?subject=help>
List-id: List for Xen developers <xen-devel.lists.sourceforge.net>
List-post: <mailto:xen-devel@lists.sourceforge.net>
List-subscribe: <https://lists.sourceforge.net/lists/listinfo/xen-devel>, <mailto:xen-devel-request@lists.sourceforge.net?subject=subscribe>
List-unsubscribe: <https://lists.sourceforge.net/lists/listinfo/xen-devel>, <mailto:xen-devel-request@lists.sourceforge.net?subject=unsubscribe>
Sender: xen-devel-admin@xxxxxxxxxxxxxxxxxxxxx
The Fedora build system is in paranoid mode, and compiles everything
with -Werror.  Additionally, it checks that the return values of calls
like read and write are checked.

The build exits with errors like:

xen/lowlevel/xc/xc.c: In function `pyxc_vmx_build':
xen/lowlevel/xc/xc.c:464: warning: ignoring return value of `sscanf', declared 
with attribute warn_unused_result
xen/lowlevel/xc/xc.c:465: warning: ignoring return value of `sscanf', declared 
with attribute warn_unused_result
error: command 'gcc' failed with exit status 1

This (trivial) patch, against yesterday's unstable snapshot, adds
these checks for a number of functions.  The obvious exception is
the dumpit function, which isn't called by anybody anyway.

I have verified that Xen still boots and can create Linux domains
with these changes applied.  I tried to stick to the various coding
styles in the different files.

Signed-off-by: Rik van Riel <riel@xxxxxxxxxx>

--- xen-unstable/tools/libxc/xc_plan9_build.c.warn      2005-02-19 
11:58:24.000000000 -0500
+++ xen-unstable/tools/libxc/xc_plan9_build.c   2005-02-19 12:02:41.000000000 
-0500
@@ -63,6 +63,7 @@
  * your image builder.
  * Xen guys, nuke this if you wish.
  */
+#if 0 /* NOT CALLED */
 void
 dumpit(int xc_handle, u32 dom,
        int start_page, int tot, unsigned long *page_array)
@@ -85,6 +86,7 @@
                munmap(vaddr, PAGE_SIZE);
        }
 }
+#endif
 int
 blah(char *b)
 {
--- xen-unstable/tools/libxc/xc_private.c.warn2 2005-02-19 12:12:44.000000000 
-0500
+++ xen-unstable/tools/libxc/xc_private.c       2005-02-19 12:14:44.000000000 
-0500
@@ -276,12 +276,14 @@
     unsigned long sz;

     lseek(fd, 0, SEEK_SET);
-    read(fd, &sig, sizeof(sig));
+    if ( read(fd, &sig, sizeof(sig)) != sizeof(sig) )
+       return 0;
     sz = lseek(fd, 0, SEEK_END);
     if ( sig == 0x8b1f ) /* GZIP signature? */
     {
         lseek(fd, -4, SEEK_END);
-        read(fd, &_sz, 4);
+        if ( read(fd, &_sz, 4) != 4 )
+               return 0;
         sz = _sz;
     }
     lseek(fd, 0, SEEK_SET);
@@ -304,6 +306,12 @@

     *size = xc_get_filesz(kernel_fd);

+    if ( *size == 0 )
+    {
+        PERROR("Could not read kernel image");
+        goto out;
+    }
+
     if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
     {
         PERROR("Could not allocate decompression state for state file");
--- xen-unstable/tools/xentrace/xentrace.c.warn 2005-02-19 12:31:19.994379665 
-0500
+++ xen-unstable/tools/xentrace/xentrace.c      2005-02-19 12:37:11.425091593 
-0500
@@ -77,8 +77,14 @@ struct timespec millis_to_timespec(unsig
  */
 void write_rec(unsigned int cpu, struct t_rec *rec, FILE *out)
 {
-    fwrite(&cpu, sizeof(cpu), 1, out);
-    fwrite(rec, sizeof(*rec), 1, out);
+    size_t written = 0;
+    written += fwrite(&cpu, sizeof(cpu), 1, out);
+    written += fwrite(rec, sizeof(*rec), 1, out);
+    if ( written != 2 )
+    {
+        PERROR("Failure to write trace record");
+        exit(EXIT_FAILURE);
+    }
 }

 /**
--- xen-unstable/tools/python/xen/lowlevel/xc/xc.c.warn 2005-02-19 
13:10:45.558410335 -0500
+++ xen-unstable/tools/python/xen/lowlevel/xc/xc.c      2005-02-19 
14:21:19.323167162 -0500
@@ -461,8 +461,10 @@ static PyObject *pyxc_vmx_build(PyObject
            sf2 = PyString_AsString(f2);
            lf3 = PyLong_AsLong(f3);
            lf4 = PyLong_AsLong(f4);
-           sscanf(sf1, "%lx", &lf1);
-           sscanf(sf2, "%lx", &lf2);
+           if (sscanf(sf1, "%lx", &lf1) != 1)
+               return NULL;
+           if (sscanf(sf2, "%lx", &lf2) != 1)
+               return NULL;

             mem_map.map[i-1].addr = lf1;
             mem_map.map[i-1].size = lf2 - lf1;


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] check read/write return values, Rik van Riel <=