netdev
[Top] [All Lists]

Apparent bug in cls_u32.c

To: netdev@xxxxxxxxxxx
Subject: Apparent bug in cls_u32.c
From: Christopher Neufeld <neufeld@xxxxxxxxxxxxx>
Date: Tue, 9 Jan 2001 10:28:33 -0500
Sender: owner-netdev@xxxxxxxxxxx
   I've run across what looks like a bounds-checking typo in
net/sched/cls_u32.c in both the 2.2 and 2.4 kernel lines.  The function
gen_new_htid() is not dead code, and is, in its entirety:

static u32 gen_new_htid(struct tc_u_common *tp_c)
{
        int i = 0x800;
 
        do {
                if (++tp_c->hgenerator == 0x7FF)
                        tp_c->hgenerator = 1;
        } while (i>0 && u32_lookup_ht(tp_c, (tp_c->hgenerator|0x800)<<20));
 
        return i > 0 ? (tp_c->hgenerator|0x800)<<20 : 0;
}


   There's nothing in that code which can modify the value of the local
variable 'i' after initialization.  As such, the FALSE branch of the
ternary operator can never be called.

   I suspect that the author's intent was to make the first part of the
while() condition:

while (--i>0 && .... )

   Could somebody please check this, and make any necessary corrections?


-- 
 Christopher Neufeld                             neufeld@xxxxxxxxxxxxx
 Home page:  http://caliban.physics.utoronto.ca/neufeld/Intro.html
 "Don't edit reality for the sake of simplicity"

<Prev in Thread] Current Thread [Next in Thread>