diff options
author | 2022-06-01 23:20:26 +0000 | |
---|---|---|
committer | 2022-06-01 23:20:26 +0000 | |
commit | 47c818f283c63fdbb7882e9aac6e2ab028666c9f (patch) | |
tree | ed42c9bdf0f0b9986849ab76c5123dc6d044455c /regress/roff/esc/B.out_ascii | |
parent | bfab7104d861ff6e91e84c914c0f977343449298 (diff) | |
download | mandoc-47c818f283c63fdbb7882e9aac6e2ab028666c9f.tar.gz mandoc-47c818f283c63fdbb7882e9aac6e2ab028666c9f.tar.zst mandoc-47c818f283c63fdbb7882e9aac6e2ab028666c9f.zip |
Fix a buffer overrun in the roff(7) escape sequence parser that could
be triggered by macro arguments ending in double backslashes, for
example if people wrote .Sq "\\" instead of the correct .Sq "\e".
The bug was hard to find because it caused a segfault only very rarely,
according to my measurements with a probability of less than one permille.
I'm sorry that the first one to hit the bug was an arm64 release build
run by deraadt@. Thanks to bluhm@ for providing access to an arm64
machine for debugging purposes. In the end, the bug turned out to be
architecture-independent.
The reason for the bug was that i assumed an invariant that does not exist.
The function roff_parse_comment() is very careful to make sure that the
input buffer does not end in an escape character before passing it on,
so i assumed this is still true when reaching roff_expand() immediately
afterwards. But roff_expand() can also be reached from roff_getarg(),
in which case there *can* be a lone escape character at the end of the
buffer in case copy mode processing found and converted a double
backslash.
Fix this by handling a trailing escape character correctly in the
function roff_escape().
The lesson here probably is to refrain from assuming an invariant
unless verifying that the invariant actually holds is reasonably
simple. In some cases, in particular for invariants that are important
but not simple, it might also make sense to assert(3) rather than just
assume the invariant. An assertion failure is so much better than a
buffer overrun...
Diffstat (limited to 'regress/roff/esc/B.out_ascii')
0 files changed, 0 insertions, 0 deletions