Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:6ee56c002f64, committed 2016-08-18
- Comitter:
- wclin
- Date:
- Thu Aug 18 08:24:37 2016 +0000
- Parent:
- 1:cfde7320b0bf
- Child:
- 3:419ee4c5e10f
- Commit message:
- Fix buffer overflow issue.
Changed in this revision
--- a/mbrtu.cpp Tue Aug 09 08:21:33 2016 +0000
+++ b/mbrtu.cpp Thu Aug 18 08:24:37 2016 +0000
@@ -27,6 +27,7 @@
*
* File: $Id: mbrtu.c,v 1.18 2007/09/12 10:15:56 wolti Exp $
*/
+#include "mbed.h"
/* ----------------------- System includes ----------------------------------*/
#include "stdlib.h"
@@ -153,7 +154,14 @@
eMBErrorCode eStatus = MB_ENOERR;
ENTER_CRITICAL_SECTION( );
- assert( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
+ //assert( usRcvBufferPos < MB_SER_PDU_SIZE_MAX ); //Wayne's workaround
+ if ( usRcvBufferPos >= MB_SER_PDU_SIZE_MAX )
+ {
+ //printf("usRcvBufferPos < MB_SER_PDU_SIZE_MAX - %d %d \r\n", usRcvBufferPos, MB_SER_PDU_SIZE_MAX );
+ eStatus = MB_EIO;
+ usRcvBufferPos = 0;
+ return eStatus;
+ }
/* Length and CRC check */
if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
--- a/port.h Tue Aug 09 08:21:33 2016 +0000
+++ b/port.h Thu Aug 18 08:24:37 2016 +0000
@@ -29,8 +29,9 @@
#define PR_BEGIN_EXTERN_C //extern "C" {
#define PR_END_EXTERN_C //}
-#define ENTER_CRITICAL_SECTION( )
-#define EXIT_CRITICAL_SECTION( )
+#define ENTER_CRITICAL_SECTION( )
+#define EXIT_CRITICAL_SECTION( )
+
typedef uint8_t BOOL;
--- a/portevent.cpp Tue Aug 09 08:21:33 2016 +0000
+++ b/portevent.cpp Thu Aug 18 08:24:37 2016 +0000
@@ -22,10 +22,11 @@
/* ----------------------- Modbus includes ----------------------------------*/
#include "mb.h"
#include "mbport.h"
+#include "mbed.h"
/* ----------------------- Variables ----------------------------------------*/
-static eMBEventType eQueuedEvent;
-static BOOL xEventInQueue;
+static volatile eMBEventType eQueuedEvent;
+static volatile BOOL xEventInQueue;
/* ----------------------- Start implementation -----------------------------*/
BOOL
@@ -53,6 +54,7 @@
*eEvent = eQueuedEvent;
xEventInQueue = FALSE;
xEventHappened = TRUE;
+ //printf("[%s %d] %x\r\n", __func__, __LINE__, *eEvent );
}
return xEventHappened;
}
--- a/portserial.cpp Tue Aug 09 08:21:33 2016 +0000
+++ b/portserial.cpp Thu Aug 18 08:24:37 2016 +0000
@@ -37,14 +37,9 @@
/* ----------------------- System Variables ---------------------------------*/
//Serial pc(USBTX, USBRX); // Cam - mbed USB serial port
-Serial pc(PG_2, PG_1); // Cam - mbed USB serial port
+Serial pc(PG_2, PG_1); // Cam - mbed serial port
-Ticker simISR; // Cam - mbed ticker
- // we don't have the TX buff empty interrupt, so
- // we just interrupt every 1 mSec and read RX & TX
- // status to simulate the proper ISRs.
-
-static BOOL RxEnable, TxEnable; // Cam - keep a static copy of the RxEnable and TxEnable
+static volatile BOOL RxEnable, TxEnable; // Cam - keep a static copy of the RxEnable and TxEnable
// status for the simulated ISR (ticker)
@@ -56,15 +51,11 @@
{
if (TxEnable)
if(pc.writeable())
- {
prvvUARTTxReadyISR();
- }
if (RxEnable)
if(pc.readable())
- {
prvvUARTRxISR();
- }
}
void
@@ -77,8 +68,6 @@
TxEnable = xTxEnable;
}
-
-#if 1
/* ----------------------- Start implementation -----------------------------*/
BOOL
xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
@@ -92,18 +81,6 @@
prvvUARTISR( );
}
-#else
-BOOL
-xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
-{
- pc.baud(ulBaudRate);
- simISR.attach_us(&prvvUARTISR, 500); // Cam - attach prvvUARTISR to a 1mS ticker to simulate serial interrupt behaviour
- // 1mS is just short of a character time at 9600 bps, so quick enough to pick
- // up status on a character by character basis.
- return TRUE;
-}
-#endif
-
BOOL
xMBPortSerialPutByte( CHAR ucByte )
{
@@ -120,7 +97,7 @@
/* Return the byte in the UARTs receive buffer. This function is called
* by the protocol stack after pxMBFrameCBByteReceived( ) has been called.
*/
- *pucByte = pc.getc();
+ * pucByte = pc.getc();
return TRUE;
}
@@ -142,6 +119,7 @@
*/
static void prvvUARTRxISR( void )
{
+ vMBPortTimersDisable();
pxMBFrameCBByteReceived( );
}