mirror of https://github.com/xemu-project/xemu.git
slirp: replace the poor-man string split with g_strsplit()
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>
This commit is contained in:
parent
c27f247865
commit
fbcd3f9a45
21
slirp/misc.c
21
slirp/misc.c
|
@ -88,11 +88,8 @@ fork_exec(struct socket *so, const char *ex)
|
||||||
socklen_t addrlen = sizeof(addr);
|
socklen_t addrlen = sizeof(addr);
|
||||||
socklen_t csaddrlen = sizeof(csaddr);
|
socklen_t csaddrlen = sizeof(csaddr);
|
||||||
int opt;
|
int opt;
|
||||||
const char *argv[256];
|
char **argv;
|
||||||
/* don't want to clobber the original */
|
int ret;
|
||||||
char *bptr;
|
|
||||||
const char *curarg;
|
|
||||||
int c, i, ret;
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
DEBUG_CALL("fork_exec");
|
DEBUG_CALL("fork_exec");
|
||||||
|
@ -156,19 +153,7 @@ fork_exec(struct socket *so, const char *ex)
|
||||||
for (s = getdtablesize() - 1; s >= 3; s--)
|
for (s = getdtablesize() - 1; s >= 3; s--)
|
||||||
close(s);
|
close(s);
|
||||||
|
|
||||||
i = 0;
|
argv = g_strsplit(ex, " ", -1);
|
||||||
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;
|
|
||||||
execvp(argv[0], (char **)argv);
|
execvp(argv[0], (char **)argv);
|
||||||
|
|
||||||
/* Ooops, failed, let's tell the user why */
|
/* Ooops, failed, let's tell the user why */
|
||||||
|
|
Loading…
Reference in New Issue