Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 Prevent lint1 from coredumping on invali...



details:   https://anonhg.NetBSD.org/src/rev/9a3feda863b7
branches:  trunk
changeset: 494360:9a3feda863b7
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jul 05 22:50:59 2000 +0000

description:
Prevent lint1 from coredumping on invalid c code such as:

    foo((sockaddr *(void *))0);

This fix is imperfect, because right now we just check the subtype
chains for NULL and we return to the caller when the loop ends, leaving
the upper layers to cope with the syntax error. Ideally we should:

        a.) return an error to the upper layer, or
        b.) not call the type analysis routines in the presence of a syntax
            error.

That would require a significant re-write which would take much more time
than I have...

diffstat:

 usr.bin/xlint/lint1/decl.c |  24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diffs (74 lines):

diff -r 9bc428a62df1 -r 9a3feda863b7 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Wed Jul 05 22:45:25 2000 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Wed Jul 05 22:50:59 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.17 2000/06/14 06:49:22 cgd Exp $ */
+/* $NetBSD: decl.c,v 1.18 2000/07/05 22:50:59 christos Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -857,10 +857,13 @@
        int     elem, elsz;
 
        elem = 1;
-       while (tp->t_tspec == ARRAY) {
+       while (tp && tp->t_tspec == ARRAY) {
                elem *= tp->t_dim;
                tp = tp->t_subt;
        }
+       if (tp == NULL)
+               return -1;
+
        switch (tp->t_tspec) {
        case FUNC:
                /* compiler takes size of function */
@@ -899,9 +902,12 @@
        int     a;
        tspec_t t;
 
-       while (tp->t_tspec == ARRAY)
+       while (tp && tp->t_tspec == ARRAY)
                tp = tp->t_subt;
 
+       if (tp == NULL)
+               return -1;
+
        if ((t = tp->t_tspec) == STRUCT || t == UNION) {
                a = tp->t_str->align;
        } else if (t == FUNC) {
@@ -1255,8 +1261,10 @@
        pqinf_t *npi;
 
        tpp = &decl->s_type;
-       while (*tpp != dcs->d_type)
+       while (*tpp && *tpp != dcs->d_type)
                tpp = &(*tpp)->t_subt;
+       if (*tpp == NULL)
+               return decl;
 
        while (pi != NULL) {
                *tpp = tp = getblk(sizeof (type_t));
@@ -1283,8 +1291,10 @@
        type_t  **tpp, *tp;
 
        tpp = &decl->s_type;
-       while (*tpp != dcs->d_type)
+       while (*tpp && *tpp != dcs->d_type)
                tpp = &(*tpp)->t_subt;
+       if (*tpp == NULL)
+           return decl;
 
        *tpp = tp = getblk(sizeof (type_t));
        tp->t_tspec = ARRAY;
@@ -1338,8 +1348,10 @@
        }
 
        tpp = &decl->s_type;
-       while (*tpp != dcs->d_nxt->d_type)
+       while (*tpp && *tpp != dcs->d_nxt->d_type)
                tpp = &(*tpp)->t_subt;
+       if (*tpp == NULL)
+           return decl;
 
        *tpp = tp = getblk(sizeof (type_t));
        tp->t_tspec = FUNC;



Home | Main Index | Thread Index | Old Index