Skip to content

Commit c8ddd06

Browse files
author
Rob Sanders
committed
Merge upstream after accepting pull 63 and 64, update README.md and spec file
1 parent 415b22c commit c8ddd06

3 files changed

Lines changed: 40 additions & 12 deletions

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ $ make
1111
$ make install
1212
```
1313

14+
Note - as of version 1.10.5 you have a compile time decision on using select()
15+
or poll() in cli_loop(). The default is to use the legacy 'select()' call.
16+
If built with 'CFLAGS=-DLIBCLI_USE_POLL make' then the poll() system call will
17+
be used instead. One additional check is being made now in cli_loop() to
18+
ensure that the passed file descriptor is in range. If not, an error message
19+
will be sent and cli_loop() will exit with CLI_ERROR.
20+
1421
This will install `libcli.so` into `/usr/local/lib`. If you want to change the
1522
location, edit Makefile.
1623

@@ -102,7 +109,9 @@ using `cli_set_context(cli, context)` and `cli_get_context(cli)` functions.
102109
You are responsible for accepting a TCP connection, and for creating a
103110
process or thread to run the cli. Once you are ready to process the
104111
connection, call `cli_loop(cli, sock)` to interact with the user on the
105-
given socket.
112+
given socket. Note that as mentioned above, if the select() call is used and
113+
sock is out of range (>= FD_SETSIZE) then cli_loop() will display an error in
114+
both the parent process and to the remote TCP connection before exiting.
106115
107116
This function will return when the user exits the cli, either by breaking the
108117
connection or entering `quit`.

libcli.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ static int cli_int_validate_pipeline(struct cli_def *cli, struct cli_pipeline *p
174174
static int cli_int_execute_pipeline(struct cli_def *cli, struct cli_pipeline *pipeline);
175175
inline void cli_int_show_pipeline(struct cli_def *cli, struct cli_pipeline *pipeline);
176176
static 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);
178179
static void cli_int_wrap_help_line(char *nameptr, char *helpptr, struct cli_comphelp *comphelp);
179180
static 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) {
203204
char *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;

libcli.spec

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ rm -rf $RPM_BUILD_ROOT
6767
%defattr(-, root, root)
6868

6969
%changelog
70-
* Wed Jan 27 2021 Rob Sa ders <rsanders@forcepoint.com> 1.10.5
70+
* Wed Jan 27 2021 Gerrit Huizenga <gerrit@us.ibm.com> 1.10.5
71+
- Add ppc64le to travis builds
72+
73+
* Wed Jan 27 2021 Rob Sanders <rsanders@forcepoint.com> 1.10.5
74+
- Add additional range chack to cli_loop() if the 'select' call is used, and
75+
punt if sockfd is out of range
76+
- Add preprocessor check (LIBCLI_USE_POLL) to toggle between using poll or
77+
select in cli_loop(). Code submitted on github by @belge-sel.
7178
- Fix possible error where cli_command_name() returns a NULL by
7279
generating full command name when a command is registered.
7380
Note - removed cli->commandname member

0 commit comments

Comments
 (0)