qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH for-3.2 11/13] slirp: replace the poor-man string sp


From: Marc-André Lureau
Subject: [Qemu-devel] [PATCH for-3.2 11/13] slirp: replace the poor-man string split with g_strsplit()
Date: Sat, 10 Nov 2018 17:45:46 +0400

Use the glib function for the work, fix a potential crash on >256 words.

Signed-off-by: Marc-André Lureau <address@hidden>
---
 slirp/misc.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/slirp/misc.c b/slirp/misc.c
index d9804f2a6d..dedc9bf6c3 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -130,11 +130,8 @@ err:
 int
 fork_exec(struct socket *so, const char *ex)
 {
-       const char *argv[256];
-       /* don't want to clobber the original */
-       char *bptr;
-       const char *curarg;
-       int opt, c, i, sp[2];
+       char **argv;
+       int opt, c, sp[2];
        pid_t pid;
 
        DEBUG_CALL("fork_exec");
@@ -161,19 +158,7 @@ fork_exec(struct socket *so, const char *ex)
                for (c = getdtablesize() - 1; c >= 3; c--)
                   close(c);
 
-               i = 0;
-               bptr = g_strdup(ex); /* No need to free() this */
-        do {
-                       /* Change the string into argv[] */
-                       curarg = bptr;
-                       while (*bptr != ' ' && *bptr != (char)0)
-                          bptr++;
-                       c = *bptr;
-                       *bptr++ = (char)0;
-                       argv[i++] = g_strdup(curarg);
-        } while (c);
-
-                argv[i] = NULL;
+        argv = g_strsplit(ex, " ", -1);
                execvp(argv[0], (char **)argv);
 
                /* Ooops, failed, let's tell the user why */
-- 
2.19.1.708.g4ede3d42df




reply via email to

[Prev in Thread] Current Thread [Next in Thread]