[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PULL 16/46] qemu-sockets: improve error reporting in uni
From: |
Michael Tokarev |
Subject: |
[Qemu-trivial] [PULL 16/46] qemu-sockets: improve error reporting in unix_listen_opts |
Date: |
Tue, 10 Feb 2015 09:34:05 +0300 |
From: Paolo Bonzini <address@hidden>
Coverity complains about not checking the returned value of mkstemp. While
at it, also improve error checking for snprintf, and refine error messages
in general.
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Michael Tokarev <address@hidden>
---
util/qemu-sockets.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index a76bb3c..cf4b91f 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -694,7 +694,7 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
- error_setg_errno(errp, errno, "Failed to create socket");
+ error_setg_errno(errp, errno, "Failed to create Unix socket");
return -1;
}
@@ -703,9 +703,15 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
if (path && strlen(path)) {
snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
} else {
- char *tmpdir = getenv("TMPDIR");
- snprintf(un.sun_path, sizeof(un.sun_path), "%s/qemu-socket-XXXXXX",
- tmpdir ? tmpdir : "/tmp");
+ const char *tmpdir = getenv("TMPDIR");
+ tmpdir = tmpdir ? tmpdir : "/tmp";
+ if (snprintf(un.sun_path, sizeof(un.sun_path), "%s/qemu-socket-XXXXXX",
+ tmpdir) >= sizeof(un.sun_path)) {
+ error_setg_errno(errp, errno,
+ "TMPDIR environment variable (%s) too large",
tmpdir);
+ goto err;
+ }
+
/*
* This dummy fd usage silences the mktemp() unsecure warning.
* Using mkstemp() doesn't make things more secure here
@@ -713,13 +719,19 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
* to unlink first and thus re-open the race window. The
* worst case possible is bind() failing, i.e. a DoS attack.
*/
- fd = mkstemp(un.sun_path); close(fd);
+ fd = mkstemp(un.sun_path);
+ if (fd < 0) {
+ error_setg_errno(errp, errno,
+ "Failed to make a temporary socket name in %s",
tmpdir);
+ goto err;
+ }
+ close(fd);
qemu_opt_set(opts, "path", un.sun_path);
}
unlink(un.sun_path);
if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {
- error_setg_errno(errp, errno, "Failed to bind socket");
+ error_setg_errno(errp, errno, "Failed to bind socket to %s",
un.sun_path);
goto err;
}
if (listen(sock, 1) < 0) {
--
2.1.4
- Re: [Qemu-trivial] [Qemu-devel] [PULL 14/46] cpu-exec: drop dead assignment, (continued)
- [Qemu-trivial] [PULL 40/46] migration: Fix warnings caused by missing 'static' attribute, Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 46/46] virtio: Fix warning caused by missing 'static' attribute, Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 05/46] Add/convert trace calls in pcnet-pci.c., Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 23/46] qemu-option: Pair g_malloc() with g_free(), not free(), Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 20/46] linux-user: wrong TARGET_SI_PAD_SIZE value for some targets., Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 33/46] kvm: g_malloc() can't fail, bury dead error handling, Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 15/46] cpu-exec: simplify icount code, Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 35/46] vnc: g_realloc() can't fail, bury dead error handling, Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 16/46] qemu-sockets: improve error reporting in unix_listen_opts,
Michael Tokarev <=
- [Qemu-trivial] [PULL 44/46] stubs: Fix warning caused by missing include statement, Michael Tokarev, 2015/02/10
- [Qemu-trivial] [PULL 22/46] qemu-option: Replace pointless use of g_malloc0() by g_malloc(), Michael Tokarev, 2015/02/10