procps/lib
Patrick Steinhardt 09a3687547 procio: fix potential out-of-bounds access when write fails
When writing to procfs via `proc_write` fails, we try to chunk the
buffer into smaller pieces to work around that issue. When searching for
the next location to split the buffer, though, we can underflow the
buffer in case the current offset is smaller than `LINELEN`. Fix the
issue by passing `cookie->offset` instead of `LINELEN` into `memrchr` in
case `cookie->offset` is smaller than `LINELEN`.

This bug can be triggered on musl-based systems, e.g. by executing

    $ sysctl kernel.printk_ratelimit=1000000000000000

As the value is out-of-range, `write` will return an error and set
`errno` to `EINVAL`. As we're only trying to write a smallish buffer
with a length smaller than `LINELEN` and as the buffer does not contain
any newlines, the call

    token = (char*)memrchr(cookie->buf+offset, '\n', LINELEN);

will underflow the buffer and crash the program.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-03-04 21:55:07 +11:00
..
.gitignore A locale-independent strtod 2016-03-10 22:27:09 +11:00
fileutils.c build-sys: split test cases in lib/ into their own files 2015-05-01 17:43:51 -07:00
procio.3 docs: fix "delimeter" typo in fprocopen man page 2019-03-04 21:54:24 +11:00
procio.c procio: fix potential out-of-bounds access when write fails 2019-03-04 21:55:07 +11:00
signals.c 0041-proc/sig.c: Harden print_given_signals(). 2018-06-09 21:35:19 +10:00
strutils.c A locale-independent strtod 2016-03-10 22:27:09 +11:00
strverscmp.c Added Cygwin build support 2016-03-12 15:07:30 +11:00
test_fileutils.c build-sys: split test cases in lib/ into their own files 2015-05-01 17:43:51 -07:00
test_process.c tests: Conditionally add prctl to test process 2016-04-17 09:11:24 +10:00
test_strtod_nol.c A locale-independent strtod 2016-03-10 22:27:09 +11:00
test_strutils.c build-sys: split test cases in lib/ into their own files 2015-05-01 17:43:51 -07:00