diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 1999-10-02 06:36:46 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 1999-10-02 06:36:46 +0000 |
commit | 3f6b495616f3d7adad11e92f69f93b5a96410c22 (patch) | |
tree | ae7677b65aad994dcd4ef7de27d734a28620981f /games/quiz/quiz.c | |
parent | 871afe20be886117e4eee5b7afa5a145be00578d (diff) |
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.
Diffstat (limited to 'games/quiz/quiz.c')
-rw-r--r-- | games/quiz/quiz.c | 11 |
1 files changed, 8 insertions, 3 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) == '\\') |