From owner-svn-src-all@freebsd.org Sat Apr 13 16:51:49 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AEBD3157D669; Sat, 13 Apr 2019 16:51:49 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4C9FB89F56; Sat, 13 Apr 2019 16:51:49 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 27B15BE01; Sat, 13 Apr 2019 16:51:49 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3DGpnEa021815; Sat, 13 Apr 2019 16:51:49 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3DGpmhM021813; Sat, 13 Apr 2019 16:51:48 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201904131651.x3DGpmhM021813@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Sat, 13 Apr 2019 16:51:48 +0000 (UTC) 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 X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: in head/usr.bin/hexdump: . tests X-SVN-Commit-Revision: 346187 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4C9FB89F56 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.949,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Apr 2019 16:51:49 -0000 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 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 }