svn commit: r346187 - in head/usr.bin/hexdump: . tests
Conrad Meyer
cem at FreeBSD.org
Tue Sep 3 14:07:37 UTC 2019
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
}
More information about the svn-src-all
mailing list