Skip to content

Commit

Permalink
client: make a connection before parsing inputs
Browse files Browse the repository at this point in the history
This shows a clear error message if the socket does not exist and when
using privileged commands.

Fix #535.
  • Loading branch information
vincentbernat committed Aug 11, 2022
1 parent 548719b commit 2541f5c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/client/lldpcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ main(int argc, char *argv[])
const char *fmt = "plain";
lldpctl_conn_t *conn = NULL;
const char *options = is_lldpctl(argv[0])?"hdvf:u:":"hdsvf:c:C:u:";
lldpctl_atom_t *configuration;

int gotinputs = 0, version = 0;
struct inputs inputs;
Expand Down Expand Up @@ -503,6 +504,13 @@ main(int argc, char *argv[])
conn = lldpctl_new_name(ctlname, NULL, NULL, NULL);
if (conn == NULL) goto end;

/* Check we have a working connection */
if ((configuration = lldpctl_get_configuration(conn)) == NULL) {
/* ctl.c already outputs an error */
goto end;
}
lldpctl_atom_dec_ref(configuration);

/* Process file inputs */
while (gotinputs && !TAILQ_EMPTY(&inputs)) {
/* coverity[use_after_free]
Expand Down

0 comments on commit 2541f5c

Please sign in to comment.