summaryrefslogtreecommitdiff
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2017-10-23 15:21:20 +0000
committerMarc Espie <espie@cvs.openbsd.org>2017-10-23 15:21:20 +0000
commit13bc0e3aaa2327b63c68fe9beeb031045c0f2396 (patch)
tree94cd7da41e288ea4de18e7ad7b9b6dbd67538b19 /usr.bin/m4
parent427b3e34a2cf05064f11372bc41ba1d72687f291 (diff)
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@
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/eval.c17
1 files changed, 8 insertions, 9 deletions
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;
}
}