Index: stable/11/usr.bin/hexdump/conv.c =================================================================== --- stable/11/usr.bin/hexdump/conv.c (revision 328499) +++ stable/11/usr.bin/hexdump/conv.c (revision 328500) @@ -1,178 +1,191 @@ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char sccsid[] = "@(#)conv.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include "hexdump.h" void conv_c(PR *pr, u_char *p, size_t bufsize) { char buf[10]; char const *str; wchar_t wc; size_t clen, oclen; int converr, pad, width; u_char peekbuf[MB_LEN_MAX]; + u_char *op; + op = NULL; + if (pr->mbleft > 0) { str = "**"; pr->mbleft--; goto strpr; } switch(*p) { case '\0': str = "\\0"; goto strpr; /* case '\a': */ case '\007': str = "\\a"; goto strpr; case '\b': str = "\\b"; goto strpr; case '\f': str = "\\f"; goto strpr; case '\n': str = "\\n"; goto strpr; case '\r': str = "\\r"; goto strpr; case '\t': str = "\\t"; goto strpr; case '\v': str = "\\v"; goto strpr; default: break; } /* * Multibyte characters are disabled for hexdump(1) for backwards * compatibility and consistency (none of its other output formats * recognize them correctly). */ converr = 0; if (odmode && MB_CUR_MAX > 1) { oclen = 0; retry: clen = mbrtowc(&wc, p, bufsize, &pr->mbstate); if (clen == 0) clen = 1; else if (clen == (size_t)-1 || (clen == (size_t)-2 && p == peekbuf)) { memset(&pr->mbstate, 0, sizeof(pr->mbstate)); + if (p == peekbuf) { + /* + * We peeked ahead, but that didn't help -- + * we either got an illegal sequence or still + * can't complete; restore original character. + */ + oclen = 0; + p = op; + } wc = *p; clen = 1; converr = 1; } else if (clen == (size_t)-2) { /* * Incomplete character; peek ahead and see if we * can complete it. */ oclen = bufsize; + op = p; bufsize = peek(p = peekbuf, MB_CUR_MAX); goto retry; } clen += oclen; } else { wc = *p; clen = 1; } if (!converr && iswprint(wc)) { if (!odmode) { *pr->cchar = 'c'; (void)printf(pr->fmt, (int)wc); - } else { + } else { *pr->cchar = 'C'; assert(strcmp(pr->fmt, "%3C") == 0); width = wcwidth(wc); assert(width >= 0); pad = 3 - width; if (pad < 0) pad = 0; (void)printf("%*s%C", pad, "", wc); pr->mbleft = clen - 1; } } else { (void)sprintf(buf, "%03o", (int)*p); str = buf; strpr: *pr->cchar = 's'; (void)printf(pr->fmt, str); } } void conv_u(PR *pr, u_char *p) { static char const * list[] = { "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "lf", "vt", "ff", "cr", "so", "si", "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fs", "gs", "rs", "us", }; /* od used nl, not lf */ if (*p <= 0x1f) { *pr->cchar = 's'; if (odmode && *p == 0x0a) (void)printf(pr->fmt, "nl"); else (void)printf(pr->fmt, list[*p]); } else if (*p == 0x7f) { *pr->cchar = 's'; (void)printf(pr->fmt, "del"); } else if (odmode && *p == 0x20) { /* od replaced space with sp */ *pr->cchar = 's'; (void)printf(pr->fmt, " sp"); } else if (isprint(*p)) { *pr->cchar = 'c'; (void)printf(pr->fmt, *p); } else { *pr->cchar = 'x'; (void)printf(pr->fmt, (int)*p); } } Index: stable/11/usr.bin/hexdump/tests/Makefile =================================================================== --- stable/11/usr.bin/hexdump/tests/Makefile (revision 328499) +++ stable/11/usr.bin/hexdump/tests/Makefile (revision 328500) @@ -1,31 +1,33 @@ # $FreeBSD$ PACKAGE= tests -ATF_TESTS_SH= hexdump_test +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_bflag_a.out ${PACKAGE}FILES+= d_hexdump_bflag_b.out ${PACKAGE}FILES+= d_hexdump_bflag_c.out ${PACKAGE}FILES+= d_hexdump_cflag_a.out ${PACKAGE}FILES+= d_hexdump_cflag_b.out ${PACKAGE}FILES+= d_hexdump_cflag_c.out ${PACKAGE}FILES+= d_hexdump_dflag_a.out ${PACKAGE}FILES+= d_hexdump_dflag_b.out ${PACKAGE}FILES+= d_hexdump_dflag_c.out ${PACKAGE}FILES+= d_hexdump_nflag_a.out ${PACKAGE}FILES+= d_hexdump_oflag_a.out ${PACKAGE}FILES+= d_hexdump_oflag_b.out ${PACKAGE}FILES+= d_hexdump_oflag_c.out ${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_xflag_a.out ${PACKAGE}FILES+= d_hexdump_xflag_b.out ${PACKAGE}FILES+= d_hexdump_xflag_c.out +${PACKAGE}FILES+= d_od_cflag_a.out +${PACKAGE}FILES+= d_od_cflag_b.out .include Index: stable/11/usr.bin/hexdump/tests/d_od_cflag_a.out =================================================================== --- stable/11/usr.bin/hexdump/tests/d_od_cflag_a.out (nonexistent) +++ stable/11/usr.bin/hexdump/tests/d_od_cflag_a.out (revision 328500) @@ -0,0 +1,3 @@ +0000000 T e s t T e s t T e s t T e s 345 +0000020 T e s t 345 +0000025 Property changes on: stable/11/usr.bin/hexdump/tests/d_od_cflag_a.out ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +on \ No newline at end of property Index: stable/11/usr.bin/hexdump/tests/d_od_cflag_b.out =================================================================== --- stable/11/usr.bin/hexdump/tests/d_od_cflag_b.out (nonexistent) +++ stable/11/usr.bin/hexdump/tests/d_od_cflag_b.out (revision 328500) @@ -0,0 +1,3 @@ +0000000 T e s t T e s t T e s t T e s т +0000020 ** Т ** е ** с ** т ** +0000031 Property changes on: stable/11/usr.bin/hexdump/tests/d_od_cflag_b.out ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +on \ No newline at end of property Index: stable/11/usr.bin/hexdump/tests/od_test.sh =================================================================== --- stable/11/usr.bin/hexdump/tests/od_test.sh (nonexistent) +++ stable/11/usr.bin/hexdump/tests/od_test.sh (revision 328500) @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright 2018 (C) Yuri Pankov +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +atf_test_case c_flag +c_flag_head() +{ + atf_set "descr" "Verify -c output (PR 224552)" +} +c_flag_body() +{ + export LC_ALL="en_US.UTF-8" + + printf 'TestTestTestTes\345Test\345' > d_od_cflag.in + atf_check -o file:"$(atf_get_srcdir)/d_od_cflag_a.out" \ + od -c d_od_cflag.in + printf 'TestTestTestTesтТест' > d_od_cflag.in + atf_check -o file:"$(atf_get_srcdir)/d_od_cflag_b.out" \ + od -c d_od_cflag.in +} + +atf_init_test_cases() +{ + atf_add_test_case c_flag +} Property changes on: stable/11/usr.bin/hexdump/tests/od_test.sh ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11 =================================================================== --- stable/11 (revision 328499) +++ stable/11 (revision 328500) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r328188-328189,328200