Skip to content

Commit

Permalink
usual/slab: sanitize object size and align.
Browse files Browse the repository at this point in the history
Too small values for both would make the code crash,
still allow them but replace with working values.

Noticed-by: Yue Du
  • Loading branch information
markokr committed Jul 7, 2013
1 parent daaa2a8 commit 2c1cb7f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions usual/slab.c
Expand Up @@ -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);
}

Expand Down

0 comments on commit 2c1cb7f

Please sign in to comment.