File tree Expand file tree Collapse file tree 4 files changed +29
-7
lines changed
Expand file tree Collapse file tree 4 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -680,4 +680,25 @@ func Test_xxd_color2()
680680 call delete (' XXDfile_colors' )
681681 unlet ! $PS1
682682endfunc
683+
684+ " this caused a buffer overflow
685+ func Test_xxd_overflow ()
686+ CheckUnix
687+ CheckExecutable /bin/ true
688+ new
689+ " we are only checking, that there are addresses in the first 5 lines
690+ let expected = [
691+ \ ' 00000000: ' ,
692+ \ ' 00000080: ' ,
693+ \ ' 00000100: ' ,
694+ \ ' 00000180: ' ,
695+ \ ' 00000200: ' ]
696+ exe " 0r! " s: xxd_cmd " -b -E -c 128 -g 256 /bin/true 2>&1"
697+ " there should not be an ASAN error message
698+ call getline (1 , ' $' )- >join (' \n' )- >assert_notmatch (' runtime error' )
699+ 6 ,$d
700+ % s /^\x\+: \zs.*/ /g
701+ call assert_equal (expected, getline (1 , 5 ))
702+ bw !
703+ endfunc
683704" vim: shiftwidth = 2 sts = 2 expandtab
Original file line number Diff line number Diff line change @@ -719,6 +719,8 @@ static char *(features[]) =
719719
720720static int included_patches [] =
721721{ /* Add new patch number below this line */
722+ /**/
723+ 1616 ,
722724/**/
723725 1615 ,
724726/**/
Original file line number Diff line number Diff line change 11# The most simplistic Makefile
22
3+ # SANITIZER_CFLAGS=-g -O0 -fsanitize-recover=all -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer
4+
35xxd : xxd.c
4- $(CC ) $(CFLAGS ) $(CPPFLAGS ) $(LDFLAGS ) -DUNIX -o xxd xxd.c $(LIBS )
6+ $(CC ) $(SANITIZER_CFLAGS ) $( CFLAGS ) $(CPPFLAGS ) $(LDFLAGS ) -DUNIX -o xxd xxd.c $(LIBS )
57
68clean :
79 rm -f xxd xxd.o
Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ extern void perror __P((char *));
148148# endif
149149#endif
150150
151- char version [] = "xxd 2025-06-15 by Juergen Weigert et al." ;
151+ char version [] = "xxd 2025-08-08 by Juergen Weigert et al." ;
152152#ifdef WIN32
153153char osver [] = " (Win32)" ;
154154#else
@@ -228,10 +228,9 @@ char osver[] = "";
228228#define LLEN_NO_COLOR \
229229 (39 /* addr: ⌈log10(ULONG_MAX)⌉ if "-d" flag given. We assume ULONG_MAX = 2**128 */ \
230230 + 2 /* ": " */ \
231- + 2 * COLS /* hex dump */ \
232- + (COLS - 1 ) /* whitespace between groups if "-g1" option given and "-c" maxed out */ \
231+ + 9 * COLS /* hex dump, worst case: bitwise output using -b */ \
233232 + 2 /* whitespace */ \
234- + COLS /* ASCII dump */ \
233+ + COLS /* ASCII dump */ \
235234 + 2 ) /* "\n\0" */
236235
237236char hexxa [] = "0123456789abcdef0123456789ABCDEF" , * hexx = hexxa ;
@@ -1182,9 +1181,7 @@ main(int argc, char *argv[])
11821181
11831182 c += addrlen + 3 + p ;
11841183 if (color )
1185- {
11861184 colors [c ] = cur_color ;
1187- }
11881185 l [c ++ ] =
11891186#if defined(__MVS__ ) && __CHARSET_LIB == 0
11901187 (e >= 64 )
You can’t perform that action at this time.
0 commit comments