diff options
author | trociny <trociny@FreeBSD.org> | 2012-01-15 18:47:24 +0000 |
---|---|---|
committer | trociny <trociny@FreeBSD.org> | 2012-01-15 18:47:24 +0000 |
commit | d4e71152bd70ed6531fa416c2cb7a63d7fa160d7 (patch) | |
tree | c6208ceb07555117d0288575ddab2dc2d79446cd /sys/kern | |
parent | 4371f8aebb7e829b24e1c2298abd87259f35148d (diff) | |
download | FreeBSD-src-d4e71152bd70ed6531fa416c2cb7a63d7fa160d7.zip FreeBSD-src-d4e71152bd70ed6531fa416c2cb7a63d7fa160d7.tar.gz |
Abrogate nchr argument in proc_getargv() and proc_getenvv(): we always want
to read strings completely to know the actual size.
As a side effect it fixes the issue with kern.proc.args and kern.proc.env
sysctls, which didn't return the size of available data when calling
sysctl(3) with the NULL argument for oldp.
Note, in get_ps_strings(), which does actual work for proc_getargv() and
proc_getenvv(), we still have a safety limit on the size of data read in
case of a corrupted procces stack.
Suggested by: kib
MFC after: 3 days
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_proc.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index bd83b59..38bc438 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1631,20 +1631,19 @@ get_proc_vector(struct thread *td, struct proc *p, char ***proc_vectorp, static int get_ps_strings(struct thread *td, struct proc *p, struct sbuf *sb, - enum proc_vector_type type, size_t nchr) + enum proc_vector_type type) { - size_t done, len, vsize; + size_t done, len, nchr, vsize; int error, i; char **proc_vector, *sptr; char pss_string[GET_PS_STRINGS_CHUNK_SZ]; PROC_ASSERT_HELD(p); - /* - * We are not going to read more than 2 * (PATH_MAX + ARG_MAX) bytes. - */ - if (nchr > 2 * (PATH_MAX + ARG_MAX)) - nchr = 2 * (PATH_MAX + ARG_MAX); + /* + * We are not going to read more than 2 * (PATH_MAX + ARG_MAX) bytes. + */ + nchr = 2 * (PATH_MAX + ARG_MAX); error = get_proc_vector(td, p, &proc_vector, &vsize, type); if (error != 0) @@ -1679,17 +1678,17 @@ done: } int -proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb, size_t nchr) +proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb) { - return (get_ps_strings(curthread, p, sb, PROC_ARG, nchr)); + return (get_ps_strings(curthread, p, sb, PROC_ARG)); } int -proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb, size_t nchr) +proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb) { - return (get_ps_strings(curthread, p, sb, PROC_ENV, nchr)); + return (get_ps_strings(curthread, p, sb, PROC_ENV)); } /* @@ -1728,7 +1727,7 @@ sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS) _PHOLD(p); PROC_UNLOCK(p); sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req); - error = proc_getargv(curthread, p, &sb, req->oldlen); + error = proc_getargv(curthread, p, &sb); error2 = sbuf_finish(&sb); PRELE(p); sbuf_delete(&sb); @@ -1780,7 +1779,7 @@ sysctl_kern_proc_env(SYSCTL_HANDLER_ARGS) } sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req); - error = proc_getenvv(curthread, p, &sb, req->oldlen); + error = proc_getenvv(curthread, p, &sb); error2 = sbuf_finish(&sb); PRELE(p); sbuf_delete(&sb); |