dfu:function: Fix number of allocated DFU function pointers
authorLukasz Majewski <l.majewski@samsung.com>
Wed, 26 Jun 2013 09:46:13 +0000 (11:46 +0200)
committerMarek Vasut <marex@denx.de>
Sun, 30 Jun 2013 16:41:08 +0000 (18:41 +0200)
This subtle change fix problem with too small amount of allocated
memory to store DFU function pointers.

One needs to allocate extra space for sentinel NULL pointer in this array
of function pointers.

With the previous code, the NULL value overwrites malloc internal data
and afterwards free(f_dfu->function) crashes.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Marek Vasut <marex@denx.de>
drivers/usb/gadget/f_dfu.c

index 178a0044c4690544019f87b29995af2ad59b9173..e3fa0e373d10328e2e70506bcfd65ed927f1f2ad 100644 (file)
@@ -589,7 +589,7 @@ static int dfu_prepare_function(struct f_dfu *f_dfu, int n)
        struct usb_interface_descriptor *d;
        int i = 0;
 
-       f_dfu->function = calloc(sizeof(struct usb_descriptor_header *), n);
+       f_dfu->function = calloc(sizeof(struct usb_descriptor_header *), n + 1);
        if (!f_dfu->function)
                goto enomem;