@samitouri / QOSamiQemu / commits / 2ec80ad928

net/slirp: allow hostfwd socket paths with dashes

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>

Michael Tokarev committed Mar 17, 2026 at 11:27 UTC 2ec80ad92840df9750e9ad5beed494cb0b202ba9
1 file changed +3 -2
net/slirp.c
+3 -2
@@ -54,7 +54,8 @@ static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
54 const char *p, *p1;
55 int len;
56 p = *pp;
57 - p1 = strchr(p, sep);
57 + /* negative sep means to search -sep from the end of buf */
58 + p1 = sep >= 0 ? strchr(p, sep) : strrchr(p, -sep);
59 if (!p1)
60 return -1;
61 len = p1 - p;
@@ -848,7 +849,7 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp)
849
850 #if !defined(WIN32) && SLIRP_CHECK_VERSION(4, 7, 0)
851 if (is_unix) {
851 - if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {
852 + if (get_str_sep(buf, sizeof(buf), &p, 0 - '-') < 0) {
853 fail_reason = "Missing - separator";
854 goto fail_syntax;
855 }