[PATCH trivial v3] net/slirp: allow hostfwd socket paths with dashes

Michael Tokarev posted 1 patch 5 days, 13 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260412071754.569575-1-mjt@tls.msk.ru
Maintainers: Samuel Thibault <samuel.thibault@ens-lyon.org>, Jason Wang <jasowang@redhat.com>, Michael Tokarev <mjt@tls.msk.ru>, Laurent Vivier <laurent@vivier.eu>
net/slirp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH trivial v3] net/slirp: allow hostfwd socket paths with dashes
Posted by Michael Tokarev 5 days, 13 hours ago
The format of hostfwd parameter is:
  hostfwd=hostpart-guestaddr:guestport
so a minus sign can not be part of the hostpart.
If hostpart specifies a unix socket path, this becomes problematic.

To solve this, look for the LAST minus/dash char in the string,
not first.

Unfortunately, [-guestaddr] is optional (defaults to 10.0.0.15),
so we still can't parse the thing in an uniform way.

Extend get_str_sep() to accept negative separator to indicate searching
from the end of buffer, to find the last occurence.  Update slirp_hostfwd
to search for the last separator when parsing unix domain socket path.

Inspired-by: Christopher Palmer-Richez <crichez@pm.me>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/347
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
v3: instead of adding an additional argument to
    get_str_sep() and changing all callers,
    (ab)use signedness of the separator.

 net/slirp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index 04925f3318..847e7dab63 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -54,7 +54,8 @@ static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
     const char *p, *p1;
     int len;
     p = *pp;
-    p1 = strchr(p, sep);
+    /* negative sep means to search -sep from the end of buf */
+    p1 = sep >= 0 ? strchr(p, sep) : strrchr(p, -sep);
     if (!p1)
         return -1;
     len = p1 - p;
@@ -848,7 +849,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_str_sep(buf, sizeof(buf), &p, 0 - '-') < 0) {
             fail_reason = "Missing - separator";
             goto fail_syntax;
         }
-- 
2.47.3