@@ -174,7 +174,8 @@ static int cli_int_validate_pipeline(struct cli_def *cli, struct cli_pipeline *p
174174static int cli_int_execute_pipeline (struct cli_def * cli , struct cli_pipeline * pipeline );
175175inline void cli_int_show_pipeline (struct cli_def * cli , struct cli_pipeline * pipeline );
176176static void cli_int_free_pipeline (struct cli_pipeline * pipeline );
177- static struct cli_command * cli_register_command_core (struct cli_def * cli , struct cli_command * parent , struct cli_command * c );
177+ static struct cli_command * cli_register_command_core (struct cli_def * cli , struct cli_command * parent ,
178+ struct cli_command * c );
178179static void cli_int_wrap_help_line (char * nameptr , char * helpptr , struct cli_comphelp * comphelp );
179180static int cli_socket_wait (int sockfd , struct timeval * tm );
180181
@@ -203,7 +204,7 @@ static ssize_t _write(int fd, const void *buf, size_t count) {
203204char * cli_int_command_name (struct cli_def * cli , struct cli_command * command ) {
204205 char * name ;
205206 char * o ;
206-
207+
207208 if (command -> full_command_name ) {
208209 free (command -> full_command_name );
209210 command -> full_command_name = NULL ;
@@ -379,10 +380,10 @@ struct cli_command *cli_register_command_core(struct cli_def *cli, struct cli_co
379380 if (!c ) return NULL ;
380381
381382 c -> parent = parent ;
382-
383+
383384 /* Go build the 'full command name' now that told it who its parent is.
384385 * If this fails, clean it up and return a NULL w/o proceeding.
385- */
386+ */
386387 if (!(c -> full_command_name = cli_int_command_name (cli , c ))) {
387388 cli_free_command (cli , c );
388389 return NULL ;
@@ -442,7 +443,7 @@ struct cli_command *cli_register_command(struct cli_def *cli, struct cli_command
442443 free (c );
443444 return NULL ;
444445 }
445-
446+
446447 return cli_register_command_core (cli , parent , c );
447448}
448449
@@ -1097,6 +1098,16 @@ int cli_loop(struct cli_def *cli, int sockfd) {
10971098 }
10981099#endif
10991100
1101+ #ifndef LIBCLI_USE_POLL
1102+ /* Do a range check *early*, and punt if we were passed a file descriptor
1103+ * that is out of the valid range
1104+ */
1105+ if (sockfd >= FD_SETSIZE ) {
1106+ fprintf (stderr , "CLI_LOOP() called with sockfd > FD_SETSIZE - aborting\n" );
1107+ cli_error (cli , "CLI_LOOP() called with sockfd > FD_SETSIZE - exiting cli_loop\n" );
1108+ return CLI_ERROR ;
1109+ }
1110+ #endif
11001111 setbuf (cli -> client , NULL );
11011112 if (cli -> banner ) cli_error (cli , "%s" , cli -> banner );
11021113
@@ -2444,19 +2455,19 @@ int cli_int_enter_buildmode(struct cli_def *cli, struct cli_pipeline_stage *stag
24442455 // Now add the four 'always there' commands to cancel current mode and to execute the command, show settings, and
24452456 // unset
24462457 c = cli_int_register_buildmode_command (cli , NULL , "cancel" , cli_int_buildmode_cancel_cback , 0 , PRIVILEGE_UNPRIVILEGED ,
2447- cli -> mode , "Cancel command" );
2458+ cli -> mode , "Cancel command" );
24482459 if (!c ) {
24492460 rc = CLI_BUILDMODE_ERROR ;
24502461 goto out ;
24512462 }
2452- c = cli_int_register_buildmode_command (cli , NULL , "execute" , cli_int_buildmode_execute_cback , 0 , PRIVILEGE_UNPRIVILEGED ,
2453- cli -> mode , "Execute command" );
2463+ c = cli_int_register_buildmode_command (cli , NULL , "execute" , cli_int_buildmode_execute_cback , 0 ,
2464+ PRIVILEGE_UNPRIVILEGED , cli -> mode , "Execute command" );
24542465 if (!c ) {
24552466 rc = CLI_BUILDMODE_ERROR ;
24562467 goto out ;
24572468 }
24582469 c = cli_int_register_buildmode_command (cli , NULL , "show" , cli_int_buildmode_show_cback , 0 , PRIVILEGE_UNPRIVILEGED ,
2459- cli -> mode , "Show current settings" );
2470+ cli -> mode , "Show current settings" );
24602471 if (!c ) {
24612472 rc = CLI_BUILDMODE_ERROR ;
24622473 goto out ;
@@ -2468,7 +2479,8 @@ int cli_int_enter_buildmode(struct cli_def *cli, struct cli_pipeline_stage *stag
24682479 goto out ;
24692480 }
24702481 o = cli_register_optarg (c , "setting" , CLI_CMD_ARGUMENT | CLI_CMD_DO_NOT_RECORD , PRIVILEGE_UNPRIVILEGED , cli -> mode ,
2471- "setting to clear" , cli_int_buildmode_unset_completor , cli_int_buildmode_unset_validator , NULL );
2482+ "setting to clear" , cli_int_buildmode_unset_completor , cli_int_buildmode_unset_validator ,
2483+ NULL );
24722484 if (!o ) {
24732485 rc = CLI_BUILDMODE_ERROR ;
24742486 goto out ;
0 commit comments