diff options
author | 2018-09-30 12:35:40 +0000 | |
---|---|---|
committer | 2018-09-30 12:35:40 +0000 | |
commit | 44dfd84e848b4bcfb9a37e4cec659dee6fd056f0 (patch) | |
tree | 399d8052b352611a34b592019214793dc3c9763f | |
parent | vstate might be used uninitialized (diff) | |
download | wireguard-openbsd-44dfd84e848b4bcfb9a37e4cec659dee6fd056f0.tar.xz wireguard-openbsd-44dfd84e848b4bcfb9a37e4cec659dee6fd056f0.zip |
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') |