Skip to content

Commit

Permalink
Fixed the file listing bug. Either in the RepRap code, or somewhere i…
Browse files Browse the repository at this point in the history
…n the SD file code, the #define for _USE_LFN is defined as fals for RepRap, true in the library file ff.c. The result is that ff.c tried to write long file names into a structure created in RepRap that was too short for them. Result - buffer overflow misery. For the moment I've commented out the bit of code in ff.c that handles long names (look for the string ******), but this needs to be tracked down and dealt with properly.
  • Loading branch information
reprappro committed Oct 29, 2013
1 parent 3c5ada0 commit 0e27ce4
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 67 deletions.
6 changes: 5 additions & 1 deletion Lwip/lwip/src/core/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file
* Transmission Control Protocol for IP
*
* This file contains common functions for the TCP implementation, such as functinos
* This file contains common functions for the TCP implementation, such as functinos
* for manipulating the data structures and the TCP timer functions. TCP functions
* related to input and output is found in tcp_in.c and tcp_out.c respectively.
*
Expand Down Expand Up @@ -42,8 +42,12 @@

#include "lwip/src/include/lwip/opt.h"

#pragma message("Testing LWIP_TCP")

#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */

#pragma message("LWIP_TCP is true")

#include "lwip/src/include/lwip/def.h"
#include "lwip/src/include/lwip/mem.h"
#include "lwip/src/include/lwip/memp.h"
Expand Down
3 changes: 2 additions & 1 deletion Lwip/lwip/src/include/lwip/def.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ extern "C" {
#define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))

#ifndef NULL
#define NULL ((void *)0)
#define NULL 0
//#define NULL ((void *)0)
#endif

/** Get the absolute difference between 2 u32_t values (correcting overflows)
Expand Down
85 changes: 43 additions & 42 deletions Lwip/lwip/src/sam/netif/ethernetif.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
return ERR_OK;
}


/**
* \brief Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
Expand Down Expand Up @@ -377,58 +378,58 @@ static struct pbuf *low_level_input(struct netif *netif)
* ethernetif.
*/

void ethernetif_input(void * pvParameters)
{
struct netif *netif = (struct netif *)pvParameters;
struct pbuf *p;

/* move received packet into a new pbuf */
p = low_level_input( netif );
if( p == NULL )
return;

if( ERR_OK != netif->input( p, netif ) )
{
pbuf_free(p);
p = NULL;
}
}


//void ethernetif_input(void * pvParameters)
//{
//
// struct netif *netif = (struct netif *)pvParameters;
// struct pbuf *p;
//
//#ifdef FREERTOS_USED
// for( ;; ) {
// do {
//#endif
// /* move received packet into a new pbuf */
// p = low_level_input( netif );
// if( p == NULL ) {
//#ifdef FREERTOS_USED
// /* No packet could be read. Wait a for an interrupt to tell us
// there is more data available. */
// vTaskDelay(100);
// }
// }while( p == NULL );
//#else
// return;
// }
//#endif
// /* move received packet into a new pbuf */
// p = low_level_input( netif );
// if( p == NULL )
// return;
//
// if( ERR_OK != netif->input( p, netif ) ) {
// pbuf_free(p);
// p = NULL;
// }
//#ifdef FREERTOS_USED
// if( ERR_OK != netif->input( p, netif ) )
// {
// pbuf_free(p);
// p = NULL;
// }
//#endif
//}


void ethernetif_input(void * pvParameters)
{

struct netif *netif = (struct netif *)pvParameters;
struct pbuf *p;

#ifdef FREERTOS_USED
for( ;; ) {
do {
#endif
/* move received packet into a new pbuf */
p = low_level_input( netif );
if( p == NULL ) {
#ifdef FREERTOS_USED
/* No packet could be read. Wait a for an interrupt to tell us
there is more data available. */
vTaskDelay(100);
}
}while( p == NULL );
#else
return;
}
#endif

if( ERR_OK != netif->input( p, netif ) ) {
pbuf_free(p);
p = NULL;
}
#ifdef FREERTOS_USED
}
#endif
}



/**
* \brief Should be called at the beginning of the program to set up the
Expand Down
51 changes: 28 additions & 23 deletions SD_HSMCI/utility/ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ void get_fileinfo ( /* No return code */
#endif
*p++ = c;
}
if (dir[8] != ' ') { /* Copy name extension */
if (dir[8] != ' ') { /* Copy name extension */
*p++ = '.';
for (i = 8; i < 11; i++) {
c = dir[i];
Expand All @@ -1885,35 +1885,41 @@ void get_fileinfo ( /* No return code */
*p++ = c;
}
}

fno->fattrib = dir[DIR_Attr]; /* Attribute */
fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */
fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */
fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */
}
*p = 0; /* Terminate SFN str by a \0 */

#if _USE_LFN
if (fno->lfname && fno->lfsize) {
TCHAR *tp = fno->lfname;
WCHAR w, *lfn;
//************ Long file names commented out by AB; seems to be #defined true here, but not
// Wherever the RepRap code is picking up the #define; hence this writes beyond the memory
// allocated to fno

//#if _USE_LFN
// if (fno->lfname && fno->lfsize) {
// TCHAR *tp = fno->lfname;
// WCHAR w, *lfn;
//
// i = 0;
// if (dj->sect && dj->lfn_idx != 0xFFFF) {/* Get LFN if available */
// lfn = dj->lfn;
// while ((w = *lfn++) != 0) { /* Get an LFN char */
//#if !_LFN_UNICODE
// w = ff_convert(w, 0); /* Unicode -> OEM conversion */
// if (!w) { i = 0; break; } /* Could not convert, no LFN */
// if (_DF1S && w >= 0x100) /* Put 1st byte if it is a DBC (always false on SBCS cfg) */
// tp[i++] = (TCHAR)(w >> 8);
//#endif
// if (i >= fno->lfsize - 1) { i = 0; break; } /* Buffer overflow, no LFN */
// tp[i++] = (TCHAR)w;
// }
// }
// tp[i] = 0; /* Terminate the LFN str by a \0 */
// }
//#endif

i = 0;
if (dj->sect && dj->lfn_idx != 0xFFFF) {/* Get LFN if available */
lfn = dj->lfn;
while ((w = *lfn++) != 0) { /* Get an LFN char */
#if !_LFN_UNICODE
w = ff_convert(w, 0); /* Unicode -> OEM conversion */
if (!w) { i = 0; break; } /* Could not convert, no LFN */
if (_DF1S && w >= 0x100) /* Put 1st byte if it is a DBC (always false on SBCS cfg) */
tp[i++] = (TCHAR)(w >> 8);
#endif
if (i >= fno->lfsize - 1) { i = 0; break; } /* Buffer overflow, no LFN */
tp[i++] = (TCHAR)w;
}
}
tp[i] = 0; /* Terminate the LFN str by a \0 */
}
#endif
}
#endif /* _FS_MINIMIZE <= 1 */

Expand Down Expand Up @@ -3016,7 +3022,6 @@ FRESULT f_readdir (
FRESULT res;
DEF_NAMEBUF;


res = validate(dj->fs, dj->id); /* Check validity of the object */
if (res == FR_OK) {
if (!fno) {
Expand Down

0 comments on commit 0e27ce4

Please sign in to comment.