Parcourir la source

telnet: disconnect a new client on cli context exhaustion

Sergey Alirzaev il y a 5 ans
Parent
commit
d7a2194036
1 fichiers modifiés avec 11 ajouts et 3 suppressions
  1. 11 3
      modules/Telnet_Server/telnet_server.c

+ 11 - 3
modules/Telnet_Server/telnet_server.c

@@ -692,9 +692,10 @@ void vBasicSocketsCommandInterpreterTask( void *pvParameters )
 #endif
 					//	recv( new_sd, &auth_tlnt_srvr_param[cur_cnt].buf, 27, 0 );
 						// Send initial options
+						bool not_enough_memory = false;
 						if(cnt_conn < NUMBER_TELNET_CONNECT){
+							cli_state_t *cli_state = 0;
 							for(uint8_t k = 0; k < NUMBER_TELNET_CONNECT; k ++){
-								cli_state_t *cli_state;
 								if(auth_tlnt_srvr_param[k].active_conn == false && (cli_state = alloc_state())){
 									auth_tlnt_srvr_param[k].active_conn = true;
 									auth_tlnt_srvr_param[k].num_connect = new_sd;
@@ -719,8 +720,15 @@ void vBasicSocketsCommandInterpreterTask( void *pvParameters )
 									break;
 								}
 							}
-							cnt_conn++;
-						} else{
+							if (!cli_state) {
+								not_enough_memory = true;
+							} else {
+								cnt_conn++;
+							}
+						} else {
+							not_enough_memory = true;
+						}
+						if (not_enough_memory) {
 							send( new_sd, pcWarningMessage, strlen( ( const char * ) pcWarningMessage ), 0 );
 							closesocket(new_sd);
 							FD_CLR(new_sd, &master_set);