diff options
author | des <des@FreeBSD.org> | 1998-10-14 18:53:36 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 1998-10-14 18:53:36 +0000 |
commit | e907ba88d048b4d54ed55f1c81dc3d19c0e877d6 (patch) | |
tree | 54711a42a37ab3c77c2017ec19d4cad84f2856dc /lib/libc/gen/exec.c | |
parent | 7af544c9f93a91365c1a65b5e233914269f981ef (diff) | |
download | FreeBSD-src-e907ba88d048b4d54ed55f1c81dc3d19c0e877d6.zip FreeBSD-src-e907ba88d048b4d54ed55f1c81dc3d19c0e877d6.tar.gz |
Make execl() vfork()-safe. This should fix potential bugs in rcp,
telnet and tip, and probably a few other apps.
Reviewed by: bde
Approved by: jkh
Diffstat (limited to 'lib/libc/gen/exec.c')
-rw-r--r-- | lib/libc/gen/exec.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c index 3b77ee9..0770ab3 100644 --- a/lib/libc/gen/exec.c +++ b/lib/libc/gen/exec.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93"; #endif static const char rcsid[] = - "$Id: exec.c,v 1.6 1997/10/14 07:23:16 bde Exp $"; + "$Id: exec.c,v 1.7 1997/11/20 15:09:38 bde Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -102,21 +102,33 @@ execl(name, arg, va_alist) #endif { va_list ap; - int sverrno; char **argv; + int n; + /* The following code is ugly, but makes execl() vfork()-safe. */ + #if __STDC__ va_start(ap, arg); #else va_start(ap); #endif - if ( (argv = buildargv(ap, arg, NULL)) ) - (void)execve(name, argv, environ); + n = 0; + while (va_arg(ap, char *) != NULL) + n++ ; va_end(ap); - sverrno = errno; - free(argv); - errno = sverrno; - return (-1); + argv = (char **)alloca((n + 1) * sizeof(*argv)); + if (argv == NULL) + return (-1); +#if __STDC__ + va_start(ap, arg); +#else + va_start(ap); +#endif + n = 0; + while ((argv[n] = va_arg(ap, char *)) != NULL) + n++; + va_end(ap); + return (execve(name, argv, environ)); } int |