From 5eb4895b552fb4f52896b9b320f7f8f7610d2258 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 1 Oct 2004 19:06:44 +0000 Subject: [PATCH] Fix some XXX --- mon_systrace.c | 36 +++++++++++++++++++++++------------- mon_systrace.h | 2 ++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/mon_systrace.c b/mon_systrace.c index fd1ee143c..28a8b62c2 100644 --- a/mon_systrace.c +++ b/mon_systrace.c @@ -55,7 +55,6 @@ static const char rcsid[] = "$Sudo$"; /* * Open the systrace device and return the fd or -1 on failure. - * XXX - warn here on error or in caller? */ static int systrace_open() @@ -192,7 +191,7 @@ systrace_attach(pid) if (nread != sizeof(msg)) { if (nread == -1 && (errno == EINTR || errno == EAGAIN)) continue; - kill(pid, SIGKILL); /* XXX - kill all pids in list */ + killall(&children, SIGKILL); _exit(nread != 0); /* shouldn't happen */ } @@ -226,9 +225,9 @@ systrace_attach(pid) handler = find_handler(msg.msg_pid, msg.msg_data.msg_ask.code); if (handler != NULL) { /* - * handler is run twice, once before we answer and once - * after. We only want to log attempts when our answer - * is accepted; otherwise we can get dupes. + * The handler is run twice, once before we answer and + * once after. We only want to log attempts when our + * answer is accepted; otherwise we can get dupes. */ cookie = handler(fd, msg.msg_pid, &msg.msg_data.msg_ask, -1, &ans.stra_policy, &ans.stra_error); @@ -273,7 +272,7 @@ systrace_attach(pid) } fail: - kill(pid, SIGKILL); /* XXX - kill all pids in list */ + killall(&children, SIGKILL); _exit(1); } @@ -461,9 +460,8 @@ systrace_read(fd, pid, addr, buf, bufsiz) /* * Read up to bufsiz bytes from addr into buf, stopping when we hit * a NUL byte. Reads are done in chunks since STRIOCIO cannot - * handle a strio_len > the actual kernel buffer. - * XXX - could pass a hint for chunksiz - * XXX - need to indicate oflow + * handle a strio_len > the actual kernel buffer. It might be nice + * to pass a starting chunksize though. */ static ssize_t read_string(fd, pid, addr, buf, bufsiz) @@ -492,7 +490,7 @@ read_string(fd, pid, addr, buf, bufsiz) } } *cp = '\0'; - return(cp - buf); + return(bufsiz >= chunksiz ? cp - buf : -1); } static schandler_t @@ -556,10 +554,8 @@ decode_args(fd, pid, askp) } if (off == (char *)askp->args[1]) continue; /* skip argv[0] */ - if ((len = read_string(fd, pid, ap, cp, ep - cp)) == -1) { - warn("STRIOCIO"); + if ((len = read_string(fd, pid, ap, cp, ep - cp)) == -1) return(-1); - } cp += len; *cp++ = ' '; /* replace NUL with a space */ } @@ -634,3 +630,17 @@ check_exec(fd, pid, askp, cookie, policyp, errorp) } return(validated); } + +/* + * Kill all pids in the list + */ +static void +killall(head, sig) + struct listhead *head; + int sig; +{ + struct childinfo *child; + + for (child = head->first; child != NULL; child = child->next) + (void) kill(child->pid, sig); +} diff --git a/mon_systrace.h b/mon_systrace.h index aa7f4fdaa..7bd5fda8d 100644 --- a/mon_systrace.h +++ b/mon_systrace.h @@ -20,6 +20,7 @@ typedef int (*schandler_t) __P((int, pid_t, struct str_msg_ask *, int, int *, int *)); struct childinfo; +struct listhead; extern struct passwd *sudo_pwdup __P((const struct passwd *, int)); extern struct passwd *sudo_getpwuid __P((uid_t)); @@ -37,6 +38,7 @@ static void new_child __P((pid_t, pid_t)); static void rm_child __P((pid_t)); static void update_child __P((pid_t, uid_t)); static struct childinfo *find_child __P((pid_t)); +static void killall __P((struct listhead *, int)); static struct listhead children; /* list of children being traced */ static int initialized; /* set to true when we are inited */ -- 2.40.0