diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-09-30 12:35:41 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-09-30 12:35:41 +0000 |
commit | ba6b42942b5780d02ade53e3fa6f4e3845b20c89 (patch) | |
tree | 3975926867acb9081e1a1fd926a3ad681f5dc18b | |
parent | 508cae080035c79a52f2de473d0a90dba322e35a (diff) |
fix the rest of the bug mitigated in the previous commit:
do not embark on an infinite loop
when -m is given and the file contains a NUL character;
OK millert@
-rw-r--r-- | regress/usr.bin/wc/wc.sh | 3 | ||||
-rw-r--r-- | usr.bin/wc/wc.c | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/regress/usr.bin/wc/wc.sh b/regress/usr.bin/wc/wc.sh index 87b7b8638be..1e52c33d73a 100644 --- a/regress/usr.bin/wc/wc.sh +++ b/regress/usr.bin/wc/wc.sh @@ -56,6 +56,9 @@ test_wc() # single byte characters test_wc "two lines\nand five words\n" " 2 5 25" +# non-printable characters +test_wc "a\033b\000c\n" " 1 1 6" + # multibyte characters test_wc "ax\0314\0200b\n" " 1 1 5" " 1 1 6" test_wc "a\0354\0277\0277b\n" " 1 1 4" \ diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c index 04f8d5c576d..237b03385c5 100644 --- a/usr.bin/wc/wc.c +++ b/usr.bin/wc/wc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wc.c,v 1.23 2018/09/29 16:17:35 cheloha Exp $ */ +/* $OpenBSD: wc.c,v 1.24 2018/09/30 12:35:40 schwarze Exp $ */ /* * Copyright (c) 1980, 1987, 1991, 1993 @@ -218,7 +218,8 @@ cnt(char *file) MB_CUR_MAX); len = 1; wc = L' '; - } + } else if (len == 0) + len = 1; if (iswspace(wc)) { gotsp = 1; if (wc == L'\n') |