Date: Tue, 03 Sep 2019 14:06:50 -0000 From: Conrad Meyer <cem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346187 - in head/usr.bin/hexdump: . tests Message-ID: <201904131651.x3DGpmhM021813@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: cem Date: Sat Apr 13 16:51:48 2019 New Revision: 346187 URL: https://svnweb.freebsd.org/changeset/base/346187 Log: hexdump(1): Exit gracefully on format strings missing conversion PR: 237263 Submitted by: Bojan Petrovic <bojan_petrovic AT fastmail.fm> Modified: head/usr.bin/hexdump/hexdump.h head/usr.bin/hexdump/parse.c head/usr.bin/hexdump/tests/hexdump_test.sh Modified: head/usr.bin/hexdump/hexdump.h ============================================================================== --- head/usr.bin/hexdump/hexdump.h Sat Apr 13 13:59:01 2019 (r346186) +++ head/usr.bin/hexdump/hexdump.h Sat Apr 13 16:51:48 2019 (r346187) @@ -88,6 +88,7 @@ void addfile(const char *); void badcnt(const char *); void badconv(const char *); void badfmt(const char *); +void badnoconv(void); void badsfmt(void); void bpad(PR *); void conv_c(PR *, u_char *, size_t); Modified: head/usr.bin/hexdump/parse.c ============================================================================== --- head/usr.bin/hexdump/parse.c Sat Apr 13 13:59:01 2019 (r346186) +++ head/usr.bin/hexdump/parse.c Sat Apr 13 16:51:48 2019 (r346187) @@ -169,7 +169,10 @@ size(FS *fs) * skip any special chars -- save precision in * case it's a %s format. */ - while (strchr(spec + 1, *++fmt)); + while (*++fmt != 0 && strchr(spec + 1, *fmt) != NULL) + ; + if (*fmt == 0) + badnoconv(); if (*fmt == '.' && isdigit(*++fmt)) { prec = atoi(fmt); while (isdigit(*++fmt)); @@ -241,10 +244,16 @@ rewrite(FS *fs) if (fu->bcnt) { sokay = USEBCNT; /* Skip to conversion character. */ - for (++p1; strchr(spec, *p1); ++p1); + while (*++p1 != 0 && strchr(spec, *p1) != NULL) + ; + if (*p1 == 0) + badnoconv(); } else { /* Skip any special chars, field width. */ - while (strchr(spec + 1, *++p1)); + while (*++p1 != 0 && strchr(spec + 1, *p1) != NULL) + ; + if (*p1 == 0) + badnoconv(); if (*p1 == '.' && isdigit(*++p1)) { sokay = USEPREC; prec = atoi(p1); @@ -511,4 +520,10 @@ void badconv(const char *ch) { errx(1, "%%%s: bad conversion character", ch); +} + +void +badnoconv(void) +{ + errx(1, "missing conversion character"); } Modified: head/usr.bin/hexdump/tests/hexdump_test.sh ============================================================================== --- head/usr.bin/hexdump/tests/hexdump_test.sh Sat Apr 13 13:59:01 2019 (r346186) +++ head/usr.bin/hexdump/tests/hexdump_test.sh Sat Apr 13 16:51:48 2019 (r346187) @@ -176,6 +176,19 @@ x_flag_body() hexdump -x "$(atf_get_srcdir)/d_hexdump_c.in" } +atf_test_case no_conv_err +no_conv_err() +{ + atf_set "descr" "Verify missing conversion char error handling" +} +no_conv_err_body() +{ + atf_check -s exit:1 -e ignore \ + hexdump -e '"%"' + atf_check -s exit:1 -e ignore \ + hexdump -e '4/2 "%"' +} + atf_init_test_cases() { atf_add_test_case b_flag @@ -188,4 +201,5 @@ atf_init_test_cases() atf_add_test_case s_flag atf_add_test_case v_flag atf_add_test_case x_flag + atf_add_test_case no_conv_err }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904131651.x3DGpmhM021813>