[PULL 01/14] net/slirp: allow hostfwd socket paths with dashes

Michael Tokarev posted 14 patches 3 weeks ago
Maintainers: Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Ani Sinha <anisinha@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Samuel Thibault <samuel.thibault@ens-lyon.org>, Jason Wang <jasowang@redhat.com>, Zhao Liu <zhao1.liu@intel.com>, Stefan Hajnoczi <stefanha@redhat.com>, Fam Zheng <fam@euphon.net>
There is a newer version of this series
[PULL 01/14] net/slirp: allow hostfwd socket paths with dashes
Posted by Michael Tokarev 3 weeks ago
From: Christopher Palmer-Richez <crichez@pm.me>

Adds get_last_str_sep, a variant of get_str_sep that checks for the last
occurence of a separator. Updates slirp_hostfwd to parse unix domain
socket paths with dashes.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/347
Signed-off-by: Christopher Palmer-Richez <crichez@pm.me>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 net/slirp.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/net/slirp.c b/net/slirp.c
index 04925f3318..968be9cc99 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -69,6 +69,26 @@ static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
     return 0;
 }
 
+static int get_last_str_sep(char *buf, int buf_size, const char **pp, int sep)
+{
+    const char *p, *p1;
+    int len;
+    p = *pp;
+    p1 = strrchr(p, sep);
+    if (!p1)
+        return -1;
+    len = p1 - p;
+    p1++;
+    if (buf_size > 0) {
+        if (len > buf_size - 1)
+            len = buf_size - 1;
+        memcpy(buf, p, len);
+        buf[len] = '\0';
+    }
+    *pp = p1;
+    return 0;
+}
+
 /* slirp network adapter */
 
 #define SLIRP_CFG_HOSTFWD 1
@@ -848,7 +868,7 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp)
 
 #if !defined(WIN32) && SLIRP_CHECK_VERSION(4, 7, 0)
     if (is_unix) {
-        if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {
+        if (get_last_str_sep(buf, sizeof(buf), &p, '-') < 0) {
             fail_reason = "Missing - separator";
             goto fail_syntax;
         }
-- 
2.47.3