diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-12-03 05:35:33 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-12-03 05:35:33 +0100 |
commit | eb9de925c63990f6b19494698e4db1eb9682e46d (patch) | |
tree | 774c129eaad9c5e0e8922885f9d310c8d6863e22 /sys/src/ape/lib/ap/plan9/_fdinfo.c | |
parent | f3842de5fd405859f0a2de9a6f9fed0311c4629c (diff) |
ape: fix more bugs, use /env and /proc instead of #e and #p, cleanup
remove envname length limitation in _envsetup()
by using allocated buffer and use /env instead of #e
use /proc and getpid() instead of #p and #c in
readprocfdinit()
fix buffer overflow in execlp(), check if name
of failed exec starts with / . or is \0
make sure not to close our own filedescriptors
for FD_CLOEXEC in execve(), fix wrong length
check for flushing buffer to /env/_fdinfo.
fix error handling cases. copy the enviroment
before decoding \1 to \0 because the strings in
environ[] array might not be writable.
remove bogus close if we fail to open ppid file
in getppid() and use /dev/ppid instead of #c/ppid
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/_fdinfo.c')
-rw-r--r-- | sys/src/ape/lib/ap/plan9/_fdinfo.c | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/sys/src/ape/lib/ap/plan9/_fdinfo.c b/sys/src/ape/lib/ap/plan9/_fdinfo.c index 85bbeca95..51d034898 100644 --- a/sys/src/ape/lib/ap/plan9/_fdinfo.c +++ b/sys/src/ape/lib/ap/plan9/_fdinfo.c @@ -2,6 +2,7 @@ #include "lib.h" #include <sys/stat.h> #include <stdlib.h> +#include <unistd.h> #include "sys9.h" #include <string.h> @@ -33,21 +34,12 @@ readprocfdinit(void) /* construct info from /proc/$pid/fd */ char buf[8192]; Fdinfo *fi; - int fd, pfd, pid, n, tot, m; + int fd, pfd, n, tot, m; char *s, *nexts; memset(buf, 0, sizeof buf); - pfd = _OPEN("#c/pid", 0); - if(pfd < 0) - return -1; - if(_PREAD(pfd, buf, 100, 0) < 0){ - _CLOSE(pfd); - return -1; - } - _CLOSE(pfd); - pid = strtoul(buf, 0, 10); - strcpy(buf, "#p/"); - _ultoa(buf+3, pid); + strcpy(buf, "/proc/"); + _ultoa(buf+6, getpid()); strcat(buf, "/fd"); pfd = _OPEN(buf, 0); if(pfd < 0) @@ -77,9 +69,7 @@ readprocfdinit(void) fd = strtoul(s, &s, 10); if(errno != 0) return -1; - if(fd >= OPEN_MAX) - continue; - if(fd == pfd) + if(fd < 0 || fd == pfd || fd >= OPEN_MAX) continue; fi = &_fdinfo[fd]; fi->flags = FD_ISOPEN; @@ -149,8 +139,6 @@ _fdinit(char *s, char *se) usedproc = 0; if(readprocfdinit() == 0) usedproc = 1; -else -_WRITE(2, "FAILED\n", 7); if(s) sfdinit(usedproc, s, se); if(!s && !usedproc) |