Re: [libvirt] [libvirt-sandbox][PATCH 4/4] libvirt-sandbox-init-qemu: Check for fopen() return value

2015-09-23 Thread Daniel P. Berrange
On Wed, Sep 23, 2015 at 11:15:24AM +0200, Michal Privoznik wrote:
> There's a problem in mount_root(): the return value of fopen() is
> not checked rather than used directly. Not only this interferes
> with pattern laid out by other areas of the code, but it's
> possibly dangerous too. If opening the config file fails, @fp may
> be dereferenced directly.
> 
> Signed-off-by: Michal Privoznik 
> ---
>  libvirt-sandbox/libvirt-sandbox-init-qemu.c | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)

ACK


Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [libvirt-sandbox][PATCH 4/4] libvirt-sandbox-init-qemu: Check for fopen() return value

2015-09-23 Thread Michal Privoznik
There's a problem in mount_root(): the return value of fopen() is
not checked rather than used directly. Not only this interferes
with pattern laid out by other areas of the code, but it's
possibly dangerous too. If opening the config file fails, @fp may
be dereferenced directly.

Signed-off-by: Michal Privoznik 
---
 libvirt-sandbox/libvirt-sandbox-init-qemu.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-qemu.c 
b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
index 054dd67..864db42 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-qemu.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
@@ -217,6 +217,8 @@ mount_entry(const char *source,
 }
 }
 
+#define MOUNTS_CONFIG_FILE SANDBOXCONFIGDIR "/mounts.cfg"
+
 static void
 mount_root(const char *path)
 {
@@ -226,7 +228,14 @@ mount_root(const char *path)
 mount_mkdir(SANDBOXCONFIGDIR, 0755);
 mount_9pfs("sandbox:config", SANDBOXCONFIGDIR, 0755, 1);
 
-FILE *fp = fopen(SANDBOXCONFIGDIR "/mounts.cfg", "r");
+FILE *fp = fopen(MOUNTS_CONFIG_FILE, "r");
+
+if (!fp) {
+fprintf(stderr, "libvirt-sandbox-init-qemu: %s: can't open %s: %s",
+__func__, MOUNTS_CONFIG_FILE, strerror(errno));
+exit_poweroff();
+}
+
 while (fgets(line, sizeof line, fp) && !foundRoot) {
 char *source = line;
 char *target = strchr(source, '\t');
-- 
2.4.9

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list