diff mbox series

[for-3.2,11/13] slirp: replace the poor-man string split with g_strsplit()

Message ID 20181110134548.14741-12-marcandre.lureau@redhat.com
State New
Headers show
Series slirp: cleanups | expand

Commit Message

Marc-André Lureau Nov. 10, 2018, 1:45 p.m. UTC
Use the glib function for the work, fix a potential crash on >256 words.

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

Comments

Samuel Thibault Nov. 10, 2018, 2:42 p.m. UTC | #1
Marc-André Lureau, le sam. 10 nov. 2018 17:45:46 +0400, a ecrit:
> Use the glib function for the work, fix a potential crash on >256 words.

Applied to my tree, thanks!

Samuel
diff mbox series

Patch

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 */