lib/stackdepot.c: check depot_index before accessing the stack slab
[linux-2.6-microblaze.git] / lib / stackdepot.c
index 81c69c0..1ec36ee 100644 (file)
@@ -202,9 +202,20 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
                               unsigned long **entries)
 {
        union handle_parts parts = { .handle = handle };
-       void *slab = stack_slabs[parts.slabindex];
+       void *slab;
        size_t offset = parts.offset << STACK_ALLOC_ALIGN;
-       struct stack_record *stack = slab + offset;
+       struct stack_record *stack;
+
+       *entries = NULL;
+       if (parts.slabindex > depot_index) {
+               WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
+                       parts.slabindex, depot_index, handle);
+               return 0;
+       }
+       slab = stack_slabs[parts.slabindex];
+       if (!slab)
+               return 0;
+       stack = slab + offset;
 
        *entries = stack->entries;
        return stack->size;