Skip to content

Commit

Permalink
hexdump: Partial lines cannot be repetitions of earlier lines.
Browse files Browse the repository at this point in the history
When checking for repetitions of earlier lines, we compare the
first nread bytes of the line against the saved line. However,
when we read a partial line, it should never be treated as a
repetition of an earlier line, even if the first bytes match.

This change fixes a bug where a partial line could be
incorrectly identified as a repetition of an earlier line.

Reported-by:	Mark Adler <[email protected]>
PR:		118723
Reviewed-by:	emaste
MFC-after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D40471
  • Loading branch information
delphij committed Jun 9, 2023
1 parent cbbac56 commit d101656
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion usr.bin/hexdump/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ get(void)
* XXX bcmp() is not quite right in the presence
* of multibyte characters.
*/
if (vflag != ALL &&
if (need == 0 && vflag != ALL &&
valid_save &&
bcmp(curp, savp, nread) == 0) {
if (vflag != DUP) {
Expand Down
3 changes: 3 additions & 0 deletions usr.bin/hexdump/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ATF_TESTS_SH= hexdump_test od_test
${PACKAGE}FILES+= d_hexdump_a.in
${PACKAGE}FILES+= d_hexdump_b.in
${PACKAGE}FILES+= d_hexdump_c.in
${PACKAGE}FILES+= d_hexdump_bug118723.in
${PACKAGE}FILES+= d_hexdump_bflag_a.out
${PACKAGE}FILES+= d_hexdump_bflag_b.out
${PACKAGE}FILES+= d_hexdump_bflag_c.out
Expand All @@ -30,6 +31,8 @@ ${PACKAGE}FILES+= d_hexdump_sflag_a.out
${PACKAGE}FILES+= d_hexdump_UCflag_a.out
${PACKAGE}FILES+= d_hexdump_UCflag_b.out
${PACKAGE}FILES+= d_hexdump_UCflag_c.out
${PACKAGE}FILES+= d_hexdump_UCflag_bug118723.out
${PACKAGE}FILES+= d_hexdump_UCvflag_bug118723.out
${PACKAGE}FILES+= d_hexdump_xflag_a_el.out
${PACKAGE}FILES+= d_hexdump_xflag_b_el.out
${PACKAGE}FILES+= d_hexdump_xflag_c_el.out
Expand Down
4 changes: 4 additions & 0 deletions usr.bin/hexdump/tests/d_hexdump_UCflag_bug118723.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
00000000 61 62 63 64 65 66 67 0a 30 31 32 33 34 35 36 0a |abcdefg.0123456.|
*
00000020 61 62 63 64 65 66 67 0a |abcdefg.|
00000028
4 changes: 4 additions & 0 deletions usr.bin/hexdump/tests/d_hexdump_UCvflag_bug118723.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
00000000 61 62 63 64 65 66 67 0a 30 31 32 33 34 35 36 0a |abcdefg.0123456.|
00000010 61 62 63 64 65 66 67 0a 30 31 32 33 34 35 36 0a |abcdefg.0123456.|
00000020 61 62 63 64 65 66 67 0a |abcdefg.|
00000028
5 changes: 5 additions & 0 deletions usr.bin/hexdump/tests/d_hexdump_bug118723.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abcdefg
0123456
abcdefg
0123456
abcdefg
8 changes: 8 additions & 0 deletions usr.bin/hexdump/tests/hexdump_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ C_flag_body()
hexdump -C "$(atf_get_srcdir)/d_hexdump_b.in"
atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \
hexdump -C "$(atf_get_srcdir)/d_hexdump_c.in"
atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_bug118723.out" \
hexdump -C "$(atf_get_srcdir)/d_hexdump_bug118723.in"
atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCvflag_bug118723.out" \
hexdump -Cv "$(atf_get_srcdir)/d_hexdump_bug118723.in"
}

atf_test_case hd_name
Expand All @@ -90,6 +94,10 @@ hd_name_body()
hd "$(atf_get_srcdir)/d_hexdump_b.in"
atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \
hd "$(atf_get_srcdir)/d_hexdump_c.in"
atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_bug118723.out" \
hd "$(atf_get_srcdir)/d_hexdump_bug118723.in"
atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCvflag_bug118723.out" \
hd -v "$(atf_get_srcdir)/d_hexdump_bug118723.in"
}

atf_test_case d_flag
Expand Down

0 comments on commit d101656

Please sign in to comment.