1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-25 07:49:18 +00:00
freebsd/usr.bin/diff
John Baldwin 3736b2dd32 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
2022-10-03 16:10:43 -07:00
..
tests diff: tests: loosen up requirements for report_identical 2022-04-18 23:04:13 -05:00
diff.1 diff: add support for --help and --version 2022-03-10 16:17:37 +00:00
diff.c diff: Re-add void argument to usage 2022-03-10 16:24:02 +00:00
diff.h
diffdir.c diff: fix failed compare when ignoring file case 2022-02-18 15:51:38 +00:00
diffreg.c diff: Fix a use after free as well as a memory leak in change(). 2022-10-03 16:10:43 -07:00
Makefile
pr.c Fix indentation in usr.bin/diff/pr.c 2022-03-04 20:46:56 +01:00
pr.h
TODO
xmalloc.c
xmalloc.h