diff mbox series

[PULL,10/64] slirp: replace the poor-man string split with g_strsplit()

Message ID 20181218230442.27887-11-samuel.thibault@ens-lyon.org
State New
Headers show
Series [PULL,01/64] slirp: associate slirp_output callback with the Slirp context | expand

Commit Message

Samuel Thibault Dec. 18, 2018, 11:03 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

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

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 slirp/misc.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/slirp/misc.c b/slirp/misc.c
index ce323ef92e..4840187750 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -88,11 +88,8 @@  fork_exec(struct socket *so, const char *ex)
 	socklen_t addrlen = sizeof(addr);
         socklen_t csaddrlen = sizeof(csaddr);
 	int opt;
-	const char *argv[256];
-	/* don't want to clobber the original */
-	char *bptr;
-	const char *curarg;
-	int c, i, ret;
+	char **argv;
+	int ret;
 	pid_t pid;
 
 	DEBUG_CALL("fork_exec");
@@ -156,19 +153,7 @@  fork_exec(struct socket *so, const char *ex)
 		for (s = getdtablesize() - 1; s >= 3; s--)
 		   close(s);
 
-		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 */