Skip to contentSkip to conversation

inet_listen_opts: add error checking

GIT PULL Applied Gerd Hoffmann 2 participants 3 messages Jun 13, 2014

lore
Share & tools
lore
#0 lore raw

Hi,

Fix for the qemu-sockets parser.

please pull,
Gerd

The following changes since commit 2a2c4830c0068d70443f3dddc4cc668f0c601b5c:

Merge remote-tracking branch 'remotes/kraxel/tags/pull-gtk-20140611-1' into staging (2014-06-12 09:51:41 +0100)

are available in the git repository at:

git://git.kraxel.org/qemu tags/pull-trivial-20140613-1

for you to fetch changes up to 8bc891279604186562f59a4239e42dcb451c60d3:

inet_listen_opts: add error checking (2014-06-13 12:34:57 +0200)

----------------------------------------------------------------
inet_listen_opts: add error checking

----------------------------------------------------------------
Gerd Hoffmann (1):
inet_listen_opts: add error checking

 util/qemu-sockets.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
#1 lore raw

Don't use atoi() function which doesn't detect errors, switch to strtol and error out on failures. Also add a range check while being at it.

---
 util/qemu-sockets.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
util/qemu-sockets.c +13 -2
index e3d29ee..a4a1e9d 100644
@@ -131,8 +131,19 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
         ai.ai_family = PF_INET6;
 
     /* lookup */
-    if (port_offset)
-        snprintf(port, sizeof(port), "%d", atoi(port) + port_offset);
+    if (port_offset) {
+        unsigned long long baseport;
+        if (parse_uint_full(port, &baseport, 10) < 0) {
+            error_setg(errp, "can't convert to a number: %s", port);
+            return -1;
+        }
+        if (baseport > 65535 ||
+            baseport + port_offset > 65535) {
+            error_setg(errp, "port %s out of range", port);
+            return -1;
+        }
+        snprintf(port, sizeof(port), "%d", (int)baseport + port_offset);
+    }
     rc = getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res);
     if (rc != 0) {
         error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
Signature · 1 line
1.8.3.1
#2 lore raw
In reply to Gerd Hoffmann
Quoted 23 lines · Gerd Hoffmann

Hi,

Fix for the qemu-sockets parser.

please pull,
Gerd

The following changes since commit 2a2c4830c0068d70443f3dddc4cc668f0c601b5c:

Merge remote-tracking branch 'remotes/kraxel/tags/pull-gtk-20140611-1' into staging (2014-06-12 09:51:41 +0100)

are available in the git repository at:

git://git.kraxel.org/qemu tags/pull-trivial-20140613-1

for you to fetch changes up to 8bc891279604186562f59a4239e42dcb451c60d3:

inet_listen_opts: add error checking (2014-06-13 12:34:57 +0200)

----------------------------------------------------------------
inet_listen_opts: add error checking

Quoted 7 lines

----------------------------------------------------------------
Gerd Hoffmann (1):
inet_listen_opts: add error checking

 util/qemu-sockets.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Applied, thanks.

-- PMM