Skip to contentSkip to conversation

libxc: check for null size file mapping

PATCH In review Paul Semel 2 participants 2 messages Feb 12, 2018

lore
Share & tools
lore

Paul Semel

author
#0 lore raw

PATCH 1/1 libxc: check for null size file mapping

Changed the error message when trying to map a null size file. When doing xl create command, we get an Invalid Kernel error when the file size is greater than zero. For zero length files, we are falling in the mmap error, and we get an Invalid parameter error, which is not explicit. With this change, we get a zero length file error.

---
 tools/libxc/xc_dom_core.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/libxc/xc_dom_core.c +6 -0
index 96e71dd2d9..9bd04cb2d5 100644
@@ -225,6 +225,12 @@ void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
                      "tried to map file which is too large");
         goto err;
     }
+    else if ( !*size )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "'%s': zero length file", filename);
+        goto err;
+    }
 
     block = malloc(sizeof(*block));
     if ( block == NULL ) {
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Paul Semel

Changed the error message when trying to map a null size file. When doing xl create command, we get an Invalid Kernel error when the file size is greater than zero. For zero length files, we are falling in the mmap error, and we get an Invalid parameter error, which is not explicit. With this change, we get a zero length file error.

This can in fact be done right after lseek, but I don't think it is important enough to ask you to rewrite your patch. :-)

Quoted 24 lines
---
 tools/libxc/xc_dom_core.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/libxc/xc_dom_core.c +6 -0
index 96e71dd2d9..9bd04cb2d5 100644
@@ -225,6 +225,12 @@ void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
                      "tried to map file which is too large");
         goto err;
     }
+    else if ( !*size )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "'%s': zero length file", filename);
+        goto err;
+    }
 
     block = malloc(sizeof(*block));
     if ( block == NULL ) {
Signature · 1 line
2.16.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel