This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Potential issue in CC3200 TFTP Function tftpResync

I'd like the request a review of the following code.  When transferring large files the TFTP process can encounter errors and doesn't correctly resync with the TFTP server.  This causes the system to incorrectly handle the error.  The code I would like reviewed is in function tftpReSync and has changes I've inserted in an effort to get around the error.  Changes I've made are commented out to the right as 12/08/2014 with either "Add" or "Del".  Five total lines impacted.

I believe the issue is in the check of "OpCode".  The problem is when the tftpFlushPackets is invoked it has the potential to overwrite the buffer which will in turn corrupt the ReadBuffer->opcode.  Then later in the function when "OpCode" is populated it is using erroneous data.  Let me know if you agree with this assessment.  The files I'm transferring are in excess of 100K and are using direct calls to the tftp functions rather than using sl_TftpRecv.



int tftpReSync( TFTP *pTftp ) { int rc = 0; unsigned short OpCode; struct tftphdr *ReadBuffer; unsigned short us_HoldOpCode; // CCGI Add debug 12/08/2014 ReadBuffer = (struct tftphdr *)pTftp->PacketBuffer; us_HoldOpCode = (unsigned short) ntohs(ReadBuffer->opcode); // CCGI Add debug 12/08/2014 /* Fluch pending input packets */ tftpFlushPackets( pTftp ); /* Abort if too many Sync errors */ pTftp->MaxSyncError--; if( pTftp->MaxSyncError == 0 ) { rc = TFTPERROR_FAILED; goto ABORT; /* Too Many Sync Errors */ } /* Back up expected block */ pTftp->NextBlock--; // OpCode = (unsigned short) ntohs(ReadBuffer->opcode); // CCGI Del debug 12/08/2014 // switch (OpCode) // CCGI Del debug 12/08/2014 switch (us_HoldOpCode) // CCGI Add debug 12/08/2014 { case TFTP_DATA: /* Resend last packet - if we're on block ZERO, resend the initial */ /* request. */ if( !pTftp->NextBlock ) tftpRRQBuild( pTftp ); else tftpACKBuild( pTftp ); break; case TFTP_ACK: