cancel
Showing results for 
Search instead for 
Did you mean: 

Fix: Bug in mass storage demo source code

maik2
Associate
Posted on January 22, 2009 at 15:30

Fix: Bug in mass storage demo source code

1 REPLY 1
maik2
Associate
Posted on May 17, 2011 at 13:00

Just want to point out a bug + fix in the mass storage demo source code:

* File Name : um0424\USBLib\demos\Mass_Storage\source\memory.c

* Version : V2.2.1

* Date : 09/22/2008

@line 35:

WORKS FOR 512 ONLY:

u32 Data_Buffer[BULK_MAX_PACKET_SIZE *2]; /* 512 bytes*/

BETTER:

u32 Data_Buffer[__MAX_BLOCK_SIZE_OF_ALL_LUNS__/4];

(you should define ''__MAX_BLOCK_SIZE_OF_ALL_LUNS__'' in your ''hw_config.h'')

BEST: ... buffer size should be maximum of ''Mass_Block_Size'' of all LUNs

---- Explanation:

In ''memory.c'' @line 72 you can see that ''MAL_Read'' is called with ''Mass_Block_Size[lun]'' as parameter which is in most cases 512 bytes (OK) BUT if it is bigger (4096 in case of CDROM) then there would be a buffer overrun...

MAL_Read( lun ,Offset ,Data_Buffer, Mass_Block_Size[lun] );

Cheers,

Maik

[ This message was edited by: maik on 22-01-2009 20:16 ]

[ This message was edited by: maik on 22-01-2009 20:18 ]