usual/slab: sanitize object size and align.
authorMarko Kreen <[email protected]>
Sun, 7 Jul 2013 13:32:28 +0000 (16:32 +0300)
committerMarko Kreen <[email protected]>
Sun, 7 Jul 2013 13:32:28 +0000 (16:32 +0300)
Too small values for both would make the code crash,
still allow them but replace with working values.

Noticed-by: Yue Du
usual/slab.c

index 41ba2f2d25f411e2f96bd623b88f6112ceadc695..d0061f8df801eb515b87a2164b8673b4cea2c659 100644 (file)
@@ -82,11 +82,20 @@ static void init_slab(struct Slab *slab, const char *name, unsigned obj_size,
        memcpy(slab->name, name, slen);
        slab->name[slen] = 0;
 
+       /* don't allow too small align, as we want to put pointers into area */
+       if (align < sizeof(long))
+               align = 0;
+
+       /* actual area for one object */
        if (align == 0)
                slab->final_size = ALIGN(obj_size);
        else
                slab->final_size = CUSTOM_ALIGN(obj_size, align);
 
+       /* allow small structs */
+       if (slab->final_size < sizeof(struct List))
+               slab->final_size = sizeof(struct List);
+
        slab_list_append(slab);
 }