@@ -572,7 +572,13 @@ int sock_connect(const struct shell *shell, size_t argc, char **argv)
572572 int ret ;
573573 char * host ;
574574 struct sockaddr target ;
575+ errno = 0 ;
575576 int sd = strtol (argv [1 ], NULL , 10 );
577+ if (errno != 0 ) {
578+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
579+ strerror (errno ));
580+ return errno ;
581+ }
576582 char * port_st = argv [3 ];
577583 int sock_idx ;
578584 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
@@ -696,7 +702,13 @@ int sock_bind(const struct shell *shell, size_t argc, char **argv)
696702 shell_help (shell );
697703 return - EINVAL ;
698704 }
705+ errno = 0 ;
699706 int sd = strtol (argv [1 ], NULL , 10 );
707+ if (errno != 0 ) {
708+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
709+ strerror (errno ));
710+ return errno ;
711+ }
700712 int sock_idx ;
701713 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
702714 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -729,7 +741,13 @@ int sock_send(const struct shell *shell, size_t argc, char **argv)
729741 return - EINVAL ;
730742 }
731743
744+ errno = 0 ;
732745 int sd = strtol (argv [1 ], NULL , 10 );
746+ if (errno != 0 ) {
747+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
748+ strerror (errno ));
749+ return errno ;
750+ }
733751 int sock_idx ;
734752 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
735753 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -761,7 +779,13 @@ int sock_sendto(const struct shell *shell, size_t argc, char **argv)
761779 return - EINVAL ;
762780 }
763781
782+ errno = 0 ;
764783 int sd = strtol (argv [1 ], NULL , 10 );
784+ if (errno != 0 ) {
785+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
786+ strerror (errno ));
787+ return errno ;
788+ }
765789 int sock_idx ;
766790 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
767791 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -850,7 +874,13 @@ int sock_sendb(const struct shell *shell, size_t argc, char **argv)
850874 return - EINVAL ;
851875 }
852876
877+ errno = 0 ;
853878 int sd = strtol (argv [1 ], NULL , 10 );
879+ if (errno != 0 ) {
880+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
881+ strerror (errno ));
882+ return errno ;
883+ }
854884 int sock_idx ;
855885 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
856886 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -945,7 +975,13 @@ int sock_recvb(const struct shell *shell, size_t argc, char **argv)
945975 return - EINVAL ;
946976 }
947977
978+ errno = 0 ;
948979 int sd = strtol (argv [1 ], NULL , 10 );
980+ if (errno != 0 ) {
981+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
982+ strerror (errno ));
983+ return errno ;
984+ }
949985 int sock_idx ;
950986 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
951987 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -1000,6 +1036,11 @@ int sock_rcv(const struct shell *shell, size_t argc, char **argv)
10001036 return - EINVAL ;
10011037 }
10021038 int sd = (int )strtol (argv [1 ], NULL , 10 );
1039+ if (errno != 0 ) {
1040+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
1041+ strerror (errno ));
1042+ return errno ;
1043+ }
10031044 int sock_idx ;
10041045 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
10051046 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -1045,6 +1086,11 @@ int sock_rcvfrom(const struct shell *shell, size_t argc, char **argv)
10451086 return - EINVAL ;
10461087 }
10471088 int sd = (int )strtol (argv [1 ], NULL , 10 );
1089+ if (errno != 0 ) {
1090+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
1091+ strerror (errno ));
1092+ return errno ;
1093+ }
10481094 int sock_idx ;
10491095 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
10501096 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -1099,7 +1145,13 @@ int sock_close(const struct shell *shell, size_t argc, char **argv)
10991145 shell_help (shell );
11001146 return - EINVAL ;
11011147 }
1148+ errno = 0 ;
11021149 int sd = strtol (argv [1 ], NULL , 10 );
1150+ if (errno != 0 ) {
1151+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
1152+ strerror (errno ));
1153+ return errno ;
1154+ }
11031155 int sock_idx ;
11041156 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
11051157 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -1136,7 +1188,13 @@ int sock_sendsms(const struct shell *shell, size_t argc, char **argv)
11361188 return - EINVAL ;
11371189 }
11381190
1191+ errno = 0 ;
11391192 int sd = strtol (argv [1 ], NULL , 10 );
1193+ if (errno != 0 ) {
1194+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
1195+ strerror (errno ));
1196+ return errno ;
1197+ }
11401198 int sock_idx ;
11411199 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
11421200 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
@@ -1168,9 +1226,19 @@ int sock_recvsms(const struct shell *shell, size_t argc, char **argv)
11681226 return - EINVAL ;
11691227 }
11701228
1229+ errno = 0 ;
11711230 int sd = strtol (argv [1 ], NULL , 10 );
1172-
1231+ if (errno != 0 ) {
1232+ shell_error (shell , "Socket %s is invalid, errno = %d; %s" , argv [1 ], errno ,
1233+ strerror (errno ));
1234+ return errno ;
1235+ }
11731236 int wait = strtol (argv [2 ], NULL , 10 );
1237+ if (errno != 0 && errno != ERANGE ) {
1238+ shell_error (shell , "Timeout %s is invalid, errno = %d; %s" , argv [1 ], errno ,
1239+ strerror (errno ));
1240+ return errno ;
1241+ }
11741242 int sock_idx ;
11751243 for (sock_idx = 0 ; sock_idx < MAX_SOCK_REC ; sock_idx ++ ) {
11761244 if (socks [sock_idx ].sd == sd && socks [sock_idx ].flags & BIT (sock_open )) {
0 commit comments