Skip to contentSkip to conversation

qemu-sockets: Fix parsing of the inet option 'to'.

PATCH Superseded Anthony PERARD 4 participants 5 messages Nov 8, 2012 – Nov 9, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-sockets: Fix parsing of the inet option 'to'.

Having a qemu command line argument like "-vnc 127.0.0.1:0,to=99" is broken. This have been break with commit 879e45c72da1569e07fbbc6a1aa2a708ea796044.

---
 qemu-sockets.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
qemu-sockets.c +3 -2
index abcd791..11d3d32 100644
@@ -551,8 +551,9 @@ static InetSocketAddress *inet_parse(const char *str, Error **errp)
     optstr = str + pos;
     h = strstr(optstr, ",to=");
     if (h) {
-        if (1 != sscanf(str, "%d%n", &to, &pos) ||
-            (str[pos] != '\0' && str[pos] != ',')) {
+        h += 4;
+        if (1 != sscanf(h, "%d%n", &to, &pos) ||
+            (h[pos] != '\0' && h[pos] != ',')) {
             error_setg(errp, "error parsing to= argument");
             goto fail;
         }
Signature · 1 line
Anthony PERARD
Tested-by on v1 1/1
#1 lore raw
Quoted 4 lines · Anthony PERARD

Having a qemu command line argument like "-vnc 127.0.0.1:0,to=99" is broken. This have been break with commit 879e45c72da1569e07fbbc6a1aa2a708ea796044.

I have the same problem, and it works on Fedora 16 after this patch.

Quoted 21 lines
---
  qemu-sockets.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
qemu-sockets.c +3 -2
index abcd791..11d3d32 100644
@@ -551,8 +551,9 @@ static InetSocketAddress *inet_parse(const char *str, Error **errp)
      optstr = str + pos;
      h = strstr(optstr, ",to=");
      if (h) {
-        if (1 != sscanf(str, "%d%n", &to, &pos) ||
-            (str[pos] != '\0' && str[pos] != ',')) {
+        h += 4;
+        if (1 != sscanf(h, "%d%n", &to, &pos) ||
+            (h[pos] != '\0' && h[pos] != ',')) {
              error_setg(errp, "error parsing to= argument");
              goto fail;
          }
Signature · 1 line
Lei
Reviewed-by on v1 1/1
#2 lore raw
In reply to Anthony PERARD

Il 08/11/2012 16:11, Anthony PERARD ha scritto:

Quoted 16 lines

Having a qemu command line argument like "-vnc 127.0.0.1:0,to=99" is broken. This have been break with commit 879e45c72da1569e07fbbc6a1aa2a708ea796044.

---
 qemu-sockets.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
qemu-sockets.c +0 -0
index abcd791..11d3d32 100644
@@ -551,8 +551,9 @@ static InetSocketAddress *inet_parse(const char *str, Error **errp)
     optstr = str + pos;

qemu-sockets.c static InetSocketAddress *inet_parse(const char *str, Error **errp) · line 559

Quoted 10 lines
qemu-sockets.c +3 -2
     h = strstr(optstr, ",to=");
     if (h) {
-        if (1 != sscanf(str, "%d%n", &to, &pos) ||
-            (str[pos] != '\0' && str[pos] != ',')) {
+        h += 4;
+        if (1 != sscanf(h, "%d%n", &to, &pos) ||
+            (h[pos] != '\0' && h[pos] != ',')) {
             error_setg(errp, "error parsing to= argument");
             goto fail;
         }

I was going to submit this exact same patch. Thanks.

I added qemu-trivial to the Cc list.

Paolo

#3 lore raw
In reply to Anthony PERARD
Quoted 14 lines · Anthony PERARD

Having a qemu command line argument like "-vnc 127.0.0.1:0,to=99" is broken. This have been break with commit 879e45c72da1569e07fbbc6a1aa2a708ea796044.

---
 qemu-sockets.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
qemu-sockets.c +0 -0
index abcd791..11d3d32 100644

qemu-sockets.c static InetSocketAddress *inet_parse(const char *str, Error **errp) · line 556

Quoted 8 lines
qemu-sockets.c +3 -2
@@ -551,8 +551,9 @@ static InetSocketAddress *inet_parse(const char *str, Error **errp)
     optstr = str + pos;
     h = strstr(optstr, ",to=");
     if (h) {
-        if (1 != sscanf(str, "%d%n", &to, &pos) ||
-            (str[pos] != '\0' && str[pos] != ',')) {
+        h += 4;
+        if (1 != sscanf(h, "%d%n", &to, &pos) ||
+            (h[pos] != '\0' && h[pos] != ',')) {

Since you're touching this line anyway, consider cleaning up the Yoda comparison to sscanf(...) != 1

Quoted 3 lines
qemu-sockets.c +0 -0
             error_setg(errp, "error parsing to= argument");
             goto fail;
         }