idtree: fix overflow for v. large ids on allocation and removal
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 6 Dec 2010 03:22:38 +0000 (13:52 +1030)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 7 Dec 2010 04:36:38 +0000 (15:36 +1100)
(Imported from SAMBA commit 09a6538969ac).

Chris Cowan tracked down a SEGV in sub_alloc: idp->level can actually
be equal to 7 (MAX_LEVEL) there, as it can be in sub_remove.

(We unfairly blamed a shift of a signed var for this crash in commit
 2db1987f5a3a).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lib/util/idtree.c

index 05c22958bf739359cc0c6f69962b067198bc27ab..09dc237f83c2eaebdecbbdcbf5068e032282d10a 100644 (file)
@@ -104,7 +104,7 @@ static int sub_alloc(struct idr_context *idp, void *ptr, int *starting_id)
 {
        int n, m, sh;
        struct idr_layer *p, *new;
-       struct idr_layer *pa[MAX_LEVEL];
+       struct idr_layer *pa[MAX_LEVEL+1];
        unsigned int l, id, oid;
        uint32_t bm;