summaryrefslogtreecommitdiffstats
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2014-05-12 19:11:19 +0000
committerespie <espie@openbsd.org>2014-05-12 19:11:19 +0000
commite2ff9f51c4bdec7286268301a0b307c3fa01b31e (patch)
treee97fc6cc09ac37e54f1078fd05e6092372c5a3de /usr.bin/m4
parentmove the ohash functions into libutil by popular demand. (diff)
downloadwireguard-openbsd-e2ff9f51c4bdec7286268301a0b307c3fa01b31e.tar.xz
wireguard-openbsd-e2ff9f51c4bdec7286268301a0b307c3fa01b31e.zip
adjust to ohash being in libutil now, and to the interface changes.
fix potential integer overflows in memory allocation (mostly for pedagogical purposes, these are unlikely to overflow in practice) move the rest of lst.lib stuff into its own directory.
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/Makefile6
-rw-r--r--usr.bin/m4/extern.h4
-rw-r--r--usr.bin/m4/gnum4.c7
-rw-r--r--usr.bin/m4/look.c25
-rw-r--r--usr.bin/m4/main.c7
-rw-r--r--usr.bin/m4/misc.c26
6 files changed, 27 insertions, 48 deletions
diff --git a/usr.bin/m4/Makefile b/usr.bin/m4/Makefile
index 16e1b6560e0..ecb89c8ede3 100644
--- a/usr.bin/m4/Makefile
+++ b/usr.bin/m4/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.12 2012/04/12 17:00:11 espie Exp $
+# $OpenBSD: Makefile,v 1.13 2014/05/12 19:11:19 espie Exp $
# -DEXTENDED
# if you want the paste & spaste macros.
@@ -8,8 +8,8 @@ CFLAGS+=-DEXTENDED -I.
CDIAGFLAGS=-W -Wall -Wstrict-prototypes -pedantic \
-Wno-unused -Wno-char-subscripts -Wno-sign-compare
-LDADD= -ly -ll -lm
-DPADD= ${LIBY} ${LIBL} ${LIBM}
+LDADD= -ly -ll -lm -lutil
+DPADD= ${LIBY} ${LIBL} ${LIBM} ${LIBUTIL}
SRCS= eval.c expr.c look.c main.c misc.c gnum4.c trace.c tokenizer.l parser.y
MAN= m4.1
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
index 38a9635acc0..d9cd64ba9f5 100644
--- a/usr.bin/m4/extern.h
+++ b/usr.bin/m4/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.53 2014/04/28 12:34:11 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.54 2014/05/12 19:11:19 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@@ -103,7 +103,7 @@ extern void pbunsigned(unsigned long);
extern void pbstr(const char *);
extern void pushback(int);
extern void *xalloc(size_t, const char *, ...);
-extern void *xallocarray(size_t, size_t, const char *, ...);
+extern void *xcalloc(size_t, size_t, const char *, ...);
extern void *xrealloc(void *, size_t, const char *, ...);
extern void *xreallocarray(void *, size_t, size_t, const char *, ...);
extern char *xstrdup(const char *);
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c
index 9d6621e2bdc..b6a64134721 100644
--- a/usr.bin/m4/gnum4.c
+++ b/usr.bin/m4/gnum4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gnum4.c,v 1.44 2014/04/28 12:34:11 espie Exp $ */
+/* $OpenBSD: gnum4.c,v 1.45 2014/05/12 19:11:19 espie Exp $ */
/*
* Copyright (c) 1999 Marc Espie
@@ -469,7 +469,8 @@ dopatsubst(const char *argv[], int argc)
if (error != 0)
exit_regerror(error, &re);
- pmatch = xallocarray(re.re_nsub+1, sizeof(regmatch_t), NULL);
+ pmatch = xreallocarray(NULL, re.re_nsub+1, sizeof(regmatch_t),
+ NULL);
do_subst(argv[2], &re,
argc > 4 && argv[4] != NULL ? argv[4] : "", pmatch);
free(pmatch);
@@ -501,7 +502,7 @@ doregexp(const char *argv[], int argc)
if (error != 0)
exit_regerror(error, &re);
- pmatch = xallocarray(re.re_nsub+1, sizeof(regmatch_t), NULL);
+ pmatch = xreallocarray(NULL, re.re_nsub+1, sizeof(regmatch_t), NULL);
if (argc == 4 || argv[4] == NULL)
do_regexpindex(argv[2], &re, pmatch);
else
diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c
index 041cbb9a868..eeec6569430 100644
--- a/usr.bin/m4/look.c
+++ b/usr.bin/m4/look.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: look.c,v 1.22 2010/09/07 19:58:09 marco Exp $ */
+/* $OpenBSD: look.c,v 1.23 2014/05/12 19:11:19 espie Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -48,43 +48,34 @@
#include "stdd.h"
#include "extern.h"
-static void *hash_alloc(size_t, void *);
-static void hash_free(void *, size_t, void *);
+static void *hash_calloc(size_t, size_t, void *);
+static void hash_free(void *, void *);
static void *element_alloc(size_t, void *);
static void setup_definition(struct macro_definition *, const char *,
const char *);
static struct ohash_info macro_info = {
offsetof(struct ndblock, name),
- NULL, hash_alloc, hash_free, element_alloc };
+ NULL, hash_calloc, hash_free, element_alloc };
struct ohash macros;
/* Support routines for hash tables. */
void *
-hash_alloc(s, u)
- size_t s;
- void *u UNUSED;
+hash_calloc(size_t n, size_t s, void *u UNUSED)
{
- void *storage = xalloc(s, "hash alloc");
- if (storage)
- memset(storage, 0, s);
+ void *storage = xcalloc(n, s, "hash alloc");
return storage;
}
void
-hash_free(p, s, u)
- void *p;
- size_t s UNUSED;
- void *u UNUSED;
+hash_free(void *p, void *u UNUSED)
{
free(p);
}
void *
-element_alloc(s, u)
- size_t s;
- void *u UNUSED;
+element_alloc(size_t s, void *u UNUSED)
{
return xalloc(s, "element alloc");
}
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index dc2b9e5f821..1dce48e50e0 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.82 2014/04/28 12:34:11 espie Exp $ */
+/* $OpenBSD: main.c,v 1.83 2014/05/12 19:11:19 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@@ -181,7 +181,7 @@ main(int argc, char *argv[])
initspaces();
STACKMAX = INITSTACKMAX;
- mstack = xallocarray(STACKMAX, sizeof(stae), NULL);
+ mstack = xreallocarray(NULL, STACKMAX, sizeof(stae), NULL);
sstack = xalloc(STACKMAX, NULL);
maxout = 0;
@@ -416,7 +416,8 @@ macro(void)
}
}
} else if (t == EOF) {
- if (sp > -1 && ilevel <= 0) {
+ if (!mimic_gnu /* you can puke right there */
+ && sp > -1 && ilevel <= 0) {
warnx( "unexpected end of input, unclosed parenthesis:");
dump_stack(paren, PARLEV);
exit(1);
diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c
index 16697a47ac5..556ecd637b9 100644
--- a/usr.bin/m4/misc.c
+++ b/usr.bin/m4/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.43 2014/04/28 12:34:11 espie Exp $ */
+/* $OpenBSD: misc.c,v 1.44 2014/05/12 19:11:19 espie Exp $ */
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
/*
@@ -311,20 +311,13 @@ xalloc(size_t n, const char *fmt, ...)
}
void *
-xallocarray(size_t s1, size_t s2, const char *fmt, ...)
+xcalloc(size_t n, size_t s, const char *fmt, ...)
{
- void *p;
-
- if (s1 && SIZE_MAX / s1 < s2) {
- errno = ENOMEM;
- p = NULL;
- } else {
- p = malloc(s1 * s2);
- }
+ void *p = calloc(n, s);
if (p == NULL) {
if (fmt == NULL)
- err(1, "malloc");
+ err(1, "calloc");
else {
va_list va;
@@ -359,19 +352,12 @@ xrealloc(void *old, size_t n, const char *fmt, ...)
void *
xreallocarray(void *old, size_t s1, size_t s2, const char *fmt, ...)
{
- void *p;
-
- if (s1 && SIZE_MAX / s1 < s2) {
- errno = ENOMEM;
- p = NULL;
- } else {
- p = realloc(old, s1 * s2);
- }
+ void *p = reallocarray(old, s1, s2);
if (p == NULL) {
free(old);
if (fmt == NULL)
- err(1, "realloc");
+ err(1, "reallocarray");
else {
va_list va;