Skip to contentSkip to conversation

slirp: Clean up net_slirp_hostfwd_remove()'s use of get_str_sep()

PATCH Applied Markus Armbruster 3 participants 3 messages Nov 16, 2011 – Nov 18, 2011 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slirp: Clean up net_slirp_hostfwd_remove()'s use of get_str_sep()

get_str_sep() can fail, but net_slirp_hostfwd_remove() doesn't check. Works, because it initializes buf[] to "", which get_str_sep() doesn't touch when it fails. Coverity doesn't like it, and neither do I.

Change it to work exactly like slirp_hostfwd().

---
 net/slirp.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
net/slirp.c +4 -5
index c6cda5d..6646ecb 100644
@@ -305,7 +305,7 @@ void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict)
 {
     struct in_addr host_addr = { .s_addr = INADDR_ANY };
     int host_port;
-    char buf[256] = "";
+    char buf[256];
     const char *src_str, *p;
     SlirpState *s;
     int is_udp = 0;
@@ -325,11 +325,10 @@ void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict)
         return;
     }
 
-    if (!src_str || !src_str[0])
-        goto fail_syntax;
-
     p = src_str;
-    get_str_sep(buf, sizeof(buf), &p, ':');
+    if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+        goto fail_syntax;
+    }
 
     if (!strcmp(buf, "tcp") || buf[0] == '\0') {
         is_udp = 0;
Signature · 1 line
1.7.6.4
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Markus Armbruster

get_str_sep() can fail, but net_slirp_hostfwd_remove() doesn't check. Works, because it initializes buf[] to "", which get_str_sep() doesn't touch when it fails. Coverity doesn't like it, and neither do I.

Change it to work exactly like slirp_hostfwd().

Stefan, can you take this? My slirp queue not fully "operative" ATM down here in Brazil.

Thanks,
Jan

Quoted 32 lines
---
 net/slirp.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
net/slirp.c +4 -5
index c6cda5d..6646ecb 100644
@@ -305,7 +305,7 @@ void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict)
 {
     struct in_addr host_addr = { .s_addr = INADDR_ANY };
     int host_port;
-    char buf[256] = "";
+    char buf[256];
     const char *src_str, *p;
     SlirpState *s;
     int is_udp = 0;
@@ -325,11 +325,10 @@ void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict)
         return;
     }
 
-    if (!src_str || !src_str[0])
-        goto fail_syntax;
-
     p = src_str;
-    get_str_sep(buf, sizeof(buf), &p, ':');
+    if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+        goto fail_syntax;
+    }
 
     if (!strcmp(buf, "tcp") || buf[0] == '\0') {
         is_udp = 0;
#2 lore raw
In reply to Markus Armbruster
Quoted 10 lines · Markus Armbruster

get_str_sep() can fail, but net_slirp_hostfwd_remove() doesn't check. Works, because it initializes buf[] to "", which get_str_sep() doesn't touch when it fails. Coverity doesn't like it, and neither do I.

Change it to work exactly like slirp_hostfwd().

---
 net/slirp.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

Thanks, applied to the trivial patches -next tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches-next

Stefan