Skip to content

Commit eeef7c7

Browse files
committed
patch 9.1.1616: xxd: possible buffer overflow with bitwise output
Problem: xxd: possible buffer overflow with bitwise output (after v9.1.1459, Xudong Cao) Solution: Update LLEN_NO_COLOR macro definition for the max line output (using bitwise output -b) fixes: #17944 closes: #17947 Signed-off-by: Christian Brabandt <[email protected]>
1 parent 887b498 commit eeef7c7

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

src/testdir/test_xxd.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,4 +680,25 @@ func Test_xxd_color2()
680680
call delete('XXDfile_colors')
681681
unlet! $PS1
682682
endfunc
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

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1616,
722724
/**/
723725
1615,
724726
/**/

src/xxd/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# The most simplistic Makefile
22

3+
# SANITIZER_CFLAGS=-g -O0 -fsanitize-recover=all -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer
4+
35
xxd: 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

68
clean:
79
rm -f xxd xxd.o

src/xxd/xxd.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff 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
153153
char 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

237236
char 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)

0 commit comments

Comments
 (0)