WIZnet Developer Forum

Serious bugs in socket.c

github.com/Wiznet/W7500P/issues/3
This code : github.com/Wiznet/W7500P/blob/m … t/socket.c

ctlsocket() and getsockopt() were seriously broken without the ‘break;’ statements.

Hope you patch this soon and also check other versions of this code…
I can not understand how these kind of errors can go unnoticed for so long, no peer review?
Good luck,
Edwin van den Oetelaar

diff -r e377caf76636 W7500P/W7500P_FW/ioLibrary/Ethernet/socket.c
--- a/W7500P/W7500P_FW/ioLibrary/Ethernet/socket.c	Tue Apr 05 21:28:05 2016 +0200
+++ b/W7500P/W7500P_FW/ioLibrary/Ethernet/socket.c	Sun Apr 10 17:20:23 2016 +0200
@@ -52,12 +52,12 @@
 #include "socket.h"
 #include "W7500x_wztoe.h"
 
-#define SOCK_ANY_PORT_NUM  0xC000;
+#define SOCK_ANY_PORT_NUM  (0xC000)
 
 static uint16_t sock_any_port = SOCK_ANY_PORT_NUM;
 static uint16_t sock_io_mode = 0;
 static uint16_t sock_is_sending = 0;
-static uint16_t sock_remained_size[_WIZCHIP_SOCK_NUM_] = {0,0,};
+static uint16_t sock_remained_size[_WIZCHIP_SOCK_NUM_] = {0,};
 static uint8_t  sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
 
 #if _WIZCHIP_ == 5200
@@ -589,6 +589,7 @@ int8_t  ctlsocket(uint8_t sn, ctlsock_ty
             break;
         case CS_GET_INTMASK:   
             *((uint8_t*)arg) = getSn_IMR(sn);
+            break;
         default:
             return SOCKERR_ARG;
     }
@@ -664,6 +665,7 @@ int8_t  getsockopt(uint8_t sn, sockopt_t
             break;
         case SO_MSS:   
             *(uint8_t*) arg = getSn_MSSR(sn);
+            break;
         case SO_DESTIP:
 	     getSn_DIPR(sn, (uint8_t*)arg);
             break;
@@ -678,8 +680,10 @@ int8_t  getsockopt(uint8_t sn, sockopt_t
 #endif      
         case SO_SENDBUF:
             *(uint16_t*) arg = getSn_TX_FSR(sn);
+            break;
         case SO_RECVBUF:
             *(uint16_t*) arg = getSn_RX_RSR(sn);
+            break;
         case SO_STATUS:
             *(uint8_t*) arg = getSn_SR(sn);
             break;

Hello, oetelaar

Thank you for your interest in W7500P.

And So sorry not to notice your issue.

We will update soon.

I checked ioLibrary in Gethub right after it. And fortunately, it is correct.

So I guess someone had mistakes during socket.c in W7500P porting from ioLibrary.

Thank you again!

lawrence

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.