opnsense-src/usr.bin/diff
John Baldwin 1f9f319919 diff: Fix a use after free as well as a memory leak in change().
When -B or -I are used, change() evaluates the lines in a hunk to
determine if it is a hunk that should be ignored.  It does this by
reading each candidate line into a mallocated buffer via preadline()
and then calling ignoreline().  Previously the buffer was freed as a
side effect of ignoreline_pattern() called from ignoreline().
However, if only -B was specified, then ignoreline_pattern() was not
called and the lines were leaked.  If both options were specified,
then ignoreline_pattern() was called before checking for a blank line
so that the second check was a use after free.

To fix, pull the free() out of ignoreline_pattern() and instead do it
up in change() so that is paired with preadline().

While here, simplify ignoreline() by checking for the -B and -I cases
individually without a separate clause for when both are set.  Also,
do the cheaper check (-B) first, and remove a false comment (this
function is only called if at least one of -I or -B are specified).

Reviewed by:	emaste
Reported by:	GCC 12 -Wuse-after-free
Differential Revision:	https://reviews.freebsd.org/D36822

(cherry picked from commit 3736b2dd32)
2022-11-11 10:18:53 -08:00
..
tests diff: tests: loosen up requirements for report_identical 2022-04-21 17:38:00 -05:00
diff.1 diff(1): Add EXAMPLES section 2020-06-19 06:48:16 +00:00
diff.c diff: fix incorrectly displaying files as duplicates 2021-02-01 14:05:25 +01:00
diff.h diff: remove stalled entries in headers 2021-05-05 10:37:08 +02:00
diffdir.c diff: Import fixes from OpenBSD 2018-06-09 21:09:24 +00:00
diffreg.c diff: Fix a use after free as well as a memory leak in change(). 2022-11-11 10:18:53 -08:00
Makefile Isolate the pr(1) related code in its own source files 2018-06-09 20:24:17 +00:00
pr.c Fix indentation in usr.bin/diff/pr.c 2022-03-12 19:18:32 +01:00
pr.h Isolate the pr(1) related code in its own source files 2018-06-09 20:24:17 +00:00
TODO Update diff(1) TODO removing what has been implemented 2020-02-07 10:18:01 +00:00
xmalloc.c asprintf returns -1, not an arbitrary value < 0. Also upon error the 2020-01-14 08:18:04 +00:00
xmalloc.h