diff options
author | 1999-10-02 06:36:45 +0000 | |
---|---|---|
committer | 1999-10-02 06:36:45 +0000 | |
commit | 90b6e068bb02bd1da7c7a50e5095a53888b72f0c (patch) | |
tree | 853ce30e153332096a8703937ff395301ea8bb9c | |
parent | pick up apxs and suexec makefiles, add BUGS section to (diff) | |
download | wireguard-openbsd-90b6e068bb02bd1da7c7a50e5095a53888b72f0c.tar.xz wireguard-openbsd-90b6e068bb02bd1da7c7a50e5095a53888b72f0c.zip |
Clean up the string handling to avoid segfaults when the regexp routines
pass each other (char *)NULLs, which used to happen on suitably invalid
data files.
-rw-r--r-- | games/quiz/quiz.c | 11 | ||||
-rw-r--r-- | games/quiz/rxp.c | 9 |
2 files changed, 15 insertions, 5 deletions
diff --git a/games/quiz/quiz.c b/games/quiz/quiz.c index 0529c78108a..dccb74c9719 100644 --- a/games/quiz/quiz.c +++ b/games/quiz/quiz.c @@ -1,4 +1,4 @@ -/* $OpenBSD: quiz.c,v 1.8 1999/06/10 22:58:24 pjanzen Exp $ */ +/* $OpenBSD: quiz.c,v 1.9 1999/10/02 06:36:45 pjanzen Exp $ */ /* $NetBSD: quiz.c,v 1.9 1995/04/22 10:16:58 cgd Exp $ */ /*- @@ -48,7 +48,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)quiz.c 8.3 (Berkeley) 5/4/95"; #else -static char rcsid[] = "$OpenBSD: quiz.c,v 1.8 1999/06/10 22:58:24 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: quiz.c,v 1.9 1999/10/02 06:36:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -273,6 +273,9 @@ quiz() s = qp->q_text; for (i = 0; i < cattwo - 1; i++) s = next_cat(s); + if (s == NULL) + errx(1, "too few fields in data file, line \"%s\"", + qp->q_text); if (!rxp_compile(s)) errx(1, "%s", rxperr); t = rxp_expand(); @@ -315,6 +318,8 @@ next_cat(s) { int esc; + if (s == NULL) + return (NULL); esc = 0; for (;;) switch (*s++) { @@ -346,7 +351,7 @@ appdstr(s, tp, len) if ((m = malloc(strlen(s) + len + 1)) == NULL) errx(1, "malloc"); - for (mp = m, sp = s; (*mp++ = *sp++) != NULL; ) + for (mp = m, sp = s; (*mp++ = *sp++) != '\0'; ) ; --mp; if (*(mp - 1) == '\\') diff --git a/games/quiz/rxp.c b/games/quiz/rxp.c index 04df2ac5fe5..43da86fe705 100644 --- a/games/quiz/rxp.c +++ b/games/quiz/rxp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rxp.c,v 1.3 1999/03/27 04:45:26 pjanzen Exp $ */ +/* $OpenBSD: rxp.c,v 1.4 1999/10/02 06:36:45 pjanzen Exp $ */ /* $NetBSD: rxp.c,v 1.5 1995/04/22 10:17:00 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)rxp.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: rxp.c,v 1.3 1999/03/27 04:45:26 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: rxp.c,v 1.4 1999/10/02 06:36:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -107,6 +107,11 @@ rxp__compile(s, first) Rxp_t *alt_ptr; int esc, err; + if (s == NULL) { + (void)snprintf(rxperr, sizeof(rxperr), + "null string sent to rxp_compile"); + return(FALSE); + } esc = 0; if (first) { rp = rxpbuf; |