@@ -31,6 +31,8 @@ SlSecParams_t g_SecParams;
3131
3232#define CONNECTION_TIMEOUT_COUNT 5000
3333
34+ #define MIN (a , b ) ((a > b) ? b : a)
35+
3436void printVersionInfo () {
3537 // get the host driver version information
3638 SlVersionFull ver ;
@@ -117,10 +119,12 @@ void startConfigurationMode() {
117119 sl_NetCfgGet (SL_MAC_ADDRESS_GET , NULL , & macAddressLen , (_u8 * )macAddressVal );
118120
119121 char ssid [MAXIMAL_SSID_LENGTH + 1 ];
120- sprintf (ssid , "%s-%s-%02X%02X%02X" , "TL04" , "fbdr000001a" ,
121- macAddressVal [SL_MAC_ADDR_LEN - 3 ],
122- macAddressVal [SL_MAC_ADDR_LEN - 2 ],
123- macAddressVal [SL_MAC_ADDR_LEN - 1 ]);
122+ snprintf (ssid ,
123+ sizeof (ssid )- 1 ,
124+ "%s-%s-%02X%02X%02X" , "TL04" , "fbdr000001a" ,
125+ macAddressVal [SL_MAC_ADDR_LEN - 3 ],
126+ macAddressVal [SL_MAC_ADDR_LEN - 2 ],
127+ macAddressVal [SL_MAC_ADDR_LEN - 1 ]);
124128 int ssidLen = strlen (ssid );
125129
126130 status = sl_WlanSet (SL_WLAN_CFG_AP_ID , WLAN_AP_OPT_SSID , ssidLen , (unsigned char * )ssid );
@@ -281,24 +285,27 @@ void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *httpServerEvent, SlHttpSe
281285 {
282286 int tokenNameLen = httpServerEvent -> EventData .httpPostData .token_name .len ;
283287 char tokenName [256 ];
284- memcpy (tokenName , httpServerEvent -> EventData .httpPostData .token_name .data , tokenNameLen );
288+ tokenNameLen = MIN (tokenNameLen , sizeof (tokenName )- 1 );
289+ strncpy (tokenName , (const char * )(httpServerEvent -> EventData .httpPostData .token_name .data ), tokenNameLen );
285290 tokenName [tokenNameLen ] = 0 ;
286291
287292 int tokenValueLen = httpServerEvent -> EventData .httpPostData .token_value .len ;
288293 char tokenValue [256 ];
289- memcpy (tokenValue , httpServerEvent -> EventData .httpPostData .token_value .data , tokenValueLen );
294+ tokenValueLen = MIN (tokenValueLen , sizeof (tokenValue )- 1 );
295+ strncpy (tokenValue , (const char * )(httpServerEvent -> EventData .httpPostData .token_value .data ), tokenValueLen );
290296 tokenValue [tokenValueLen ] = 0 ;
291297
292298 UART_PRINT ("[Blink] Parameter name : %s\r\n" , tokenName );
293299 UART_PRINT (" Parameter value : %s\r\n" , tokenValue );
294300
295- if ((0 == memcmp (tokenName , "__SL_P_USZ" , tokenNameLen ))
296- && (0 == memcmp ( tokenValue , "Add" , tokenValueLen ))) {
301+ if ((0 == strcmp (tokenName , "__SL_P_USZ" ))
302+ && (0 == strcmp ( tokenValue , "Add" ))) {
297303 g_ProvisioningDone = 1 ;
298- } else if (0 == memcmp (tokenName , "__SL_P_USA" , tokenNameLen )) {
299- memcpy (g_WlanSSID , tokenValue , tokenValueLen );
304+ } else if (0 == strcmp (tokenName , "__SL_P_USA" )) {
305+ tokenValueLen = MIN (tokenValueLen , sizeof (g_WlanSSID )- 1 );
306+ strncpy ((char * )g_WlanSSID , tokenValue , tokenValueLen );
300307 g_WlanSSID [tokenValueLen ] = 0 ;
301- } else if (0 == memcmp (tokenName , "__SL_P_USB" , tokenNameLen )) {
308+ } else if (0 == strcmp (tokenName , "__SL_P_USB" )) {
302309 if (tokenValue [0 ] == '0' ) {
303310 g_SecParams .Type = SL_SEC_TYPE_OPEN ;
304311 } else if (tokenValue [0 ] == '1' ) {
@@ -308,25 +315,31 @@ void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *httpServerEvent, SlHttpSe
308315 } else {
309316 g_SecParams .Type = SL_SEC_TYPE_OPEN ;
310317 }
311- } else if (0 == memcmp (tokenName , "__SL_P_USC" , tokenNameLen )) {
312- memcpy (g_WlanSecurityKey , tokenValue , tokenValueLen );
318+ } else if (0 == strcmp (tokenName , "__SL_P_USC" )) {
319+ tokenValueLen = MIN (tokenValueLen , sizeof (g_WlanSecurityKey )- 1 );
320+ strncpy ((char * )g_WlanSecurityKey , tokenValue , tokenValueLen );
313321 g_WlanSecurityKey [tokenValueLen ] = 0 ;
314322 g_SecParams .Key = g_WlanSecurityKey ;
315323 g_SecParams .KeyLen = tokenValueLen ;
316- } else if (0 == memcmp (tokenName , "__SL_P_USD" , tokenNameLen )) {
317- memcpy (g_ApplicationID , tokenValue , tokenValueLen );
324+ } else if (0 == strcmp (tokenName , "__SL_P_USD" )) {
325+ tokenValueLen = MIN (tokenValueLen , sizeof (g_ApplicationID )- 1 );
326+ strncpy (g_ApplicationID , tokenValue , tokenValueLen );
318327 g_ApplicationID [tokenValueLen ] = 0 ;
319- } else if (0 == memcmp (tokenName , "__SL_P_USE" , tokenNameLen )) {
320- memcpy (g_ClientKey , tokenValue , tokenValueLen );
328+ } else if (0 == strcmp (tokenName , "__SL_P_USE" )) {
329+ tokenValueLen = MIN (tokenValueLen , sizeof (g_ClientKey )- 1 );
330+ strncpy (g_ClientKey , tokenValue , tokenValueLen );
321331 g_ClientKey [tokenValueLen ] = 0 ;
322- } else if (0 == memcmp (tokenName , "__SL_P_USF" , tokenNameLen )) {
323- memcpy (g_InstallationID , tokenValue , tokenValueLen );
332+ } else if (0 == strcmp (tokenName , "__SL_P_USF" )) {
333+ tokenValueLen = MIN (tokenValueLen , sizeof (g_InstallationID )- 1 );
334+ strncpy (g_InstallationID , tokenValue , tokenValueLen );
324335 g_InstallationID [tokenValueLen ] = 0 ;
325- } else if (0 == memcmp (tokenName , "__SL_P_USG" , tokenNameLen )) {
326- memcpy (g_SessionToken , tokenValue , tokenValueLen );
336+ } else if (0 == strcmp (tokenName , "__SL_P_USG" )) {
337+ tokenValueLen = MIN (tokenValueLen , sizeof (g_SessionToken )- 1 );
338+ strncpy (g_SessionToken , tokenValue , tokenValueLen );
327339 g_SessionToken [tokenValueLen ] = 0 ;
328- } else if (0 == memcmp (tokenName , "__SL_P_USH" , tokenNameLen )) {
329- memcpy (g_DeviceName , tokenValue , tokenValueLen );
340+ } else if (0 == strcmp (tokenName , "__SL_P_USH" )) {
341+ tokenValueLen = MIN (tokenValueLen , sizeof (g_DeviceName )- 1 );
342+ strncpy (g_DeviceName , tokenValue , tokenValueLen );
330343 g_DeviceName [tokenValueLen ] = 0 ;
331344 }
332345 }
0 commit comments