From: Vincent Bernat Date: Thu, 11 Aug 2022 16:24:39 +0000 (+0200) Subject: client: make a connection before parsing inputs X-Git-Tag: 1.0.15~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2541f5c057122788041c59366b9a89c7e2566186;p=thirdparty%2Flldpd.git client: make a connection before parsing inputs This shows a clear error message if the socket does not exist and when using privileged commands. Fix #535. --- diff --git a/src/client/lldpcli.c b/src/client/lldpcli.c index a7d9be4b..3af19204 100644 --- a/src/client/lldpcli.c +++ b/src/client/lldpcli.c @@ -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; @@ -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]