Skip to main content
maik2
Associate
January 22, 2009
Question

Fix: Bug in mass storage demo source code

  • January 22, 2009
  • 1 reply
  • 497 views
Posted on January 22, 2009 at 15:30

Fix: Bug in mass storage demo source code

    This topic has been closed for replies.

    1 reply

    maik2
    maik2Author
    Associate
    May 17, 2011
    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 ]