]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
client: make a connection before parsing inputs
authorVincent Bernat <vincent@bernat.ch>
Thu, 11 Aug 2022 16:24:39 +0000 (18:24 +0200)
committerVincent Bernat <vincent@bernat.ch>
Thu, 11 Aug 2022 16:24:39 +0000 (18:24 +0200)
This shows a clear error message if the socket does not exist and when
using privileged commands.

Fix #535.

src/client/lldpcli.c

index a7d9be4b4b20baf35433b0bf2283b013bc7167f9..3af19204d2e26f89f8161cfd9e97c672df6cc392 100644 (file)
@@ -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]