diff options
author | 2017-10-23 15:21:19 +0000 | |
---|---|---|
committer | 2017-10-23 15:21:19 +0000 | |
commit | b6ff91d1a140a2349847dc31c344dadf3c01ea74 (patch) | |
tree | db6bfb1a98f3cf88fa4e9e5d5687e769b805b7a9 | |
parent | Close the socket (and dfd) in at(1) child processes (diff) | |
download | wireguard-openbsd-b6ff91d1a140a2349847dc31c344dadf3c01ea74.tar.xz wireguard-openbsd-b6ff91d1a140a2349847dc31c344dadf3c01ea74.zip |
ifelse is special, fix argv parsing to avoid segfault
problem noticed by Matthew Green (netbsd), slightly different fix
so that argc counting makes more sense.
we might want to warn on wrong number of parameters later, but this is
somewhat inconsistent depending on the builtin right now.
okay millert@
-rw-r--r-- | regress/usr.bin/m4/Makefile | 8 | ||||
-rw-r--r-- | regress/usr.bin/m4/args3.m4 | 3 | ||||
-rw-r--r-- | usr.bin/m4/eval.c | 17 |
3 files changed, 17 insertions, 11 deletions
diff --git a/regress/usr.bin/m4/Makefile b/regress/usr.bin/m4/Makefile index 08143728057..cc452c471fe 100644 --- a/regress/usr.bin/m4/Makefile +++ b/regress/usr.bin/m4/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.33 2017/06/15 13:48:42 bcallah Exp $ +# $OpenBSD: Makefile,v 1.34 2017/10/23 15:21:19 espie Exp $ FIBOMAX=25 M4=m4 @@ -9,7 +9,8 @@ CLEANFILES+= ff_after_dnl.m4 strangequotes.m4 fibo.out REGRESS_TARGETS= test-ff_after_dnl test-m4wrap test-m4wrap2 \ test-m4wrap3 test-gm4wrap3 test-fibo \ test-patterns trip test-strangequotes test-redef test-redef2 test-quotes \ - test-weird test-args test-args2 test-esyscmd test-eval test-gnupatterns \ + test-weird test-args test-args2 test-args3 \ + test-esyscmd test-eval test-gnupatterns \ test-gnupatterns2 test-comments test-synch1 test-synch1bis \ test-gnuformat test-includes test-dumpdef test-gnuprefix \ test-translit test-translit2 test-gnutranslit2 \ @@ -82,6 +83,9 @@ test-args2: test-args: ${M4} ${.CURDIR}/args.m4 | diff - ${.CURDIR}/args.out +test-args3: + ${M4} ${.CURDIR}/args3.m4 >/dev/null + test-includes: ${M4} -I${.CURDIR} ${.CURDIR}/includes.m4 | \ diff - ${.CURDIR}/includes.out diff --git a/regress/usr.bin/m4/args3.m4 b/regress/usr.bin/m4/args3.m4 new file mode 100644 index 00000000000..a6879d38c39 --- /dev/null +++ b/regress/usr.bin/m4/args3.m4 @@ -0,0 +1,3 @@ +dnl invalid number of parameters for doifelse +dnl do not segfault +ifelse(A, "s",,,) diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 0ce407b94e7..8b277a2e09d 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.75 2017/06/15 13:48:42 bcallah Exp $ */ +/* $OpenBSD: eval.c,v 1.76 2017/10/23 15:21:19 espie Exp $ */ /* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ /* @@ -195,8 +195,7 @@ expand_builtin(const char *argv[], int argc, int td) } case IFELTYPE: - if (argc > 4) - doifelse(argv, argc); + doifelse(argv, argc); break; case IFDFTYPE: @@ -689,17 +688,17 @@ dotrace(const char *argv[], int argc, int on) static void doifelse(const char *argv[], int argc) { - cycle { - if (STREQ(argv[2], argv[3])) + while (argc > 4) { + if (STREQ(argv[2], argv[3])) { pbstr(argv[4]); - else if (argc == 6) + break; + } else if (argc == 6) { pbstr(argv[5]); - else if (argc > 6) { + break; + } else { argv += 3; argc -= 3; - continue; } - break; } } |