]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Ensure an empty string does not get printed for host/domain
authorDonald Sharp <sharpd@nvidia.com>
Thu, 21 Apr 2022 18:13:01 +0000 (14:13 -0400)
committermergify-bot <noreply@mergify.com>
Mon, 25 Apr 2022 04:41:58 +0000 (04:41 +0000)
End operator is showing:
!
frr version 8.0.1
frr defaults traditional
hostname test.example.com
domainname

domainname should not be printed in this case at all.  I do not
see any mechanism in current code that this could happen, but
what do I know?  Put some extra stupid insurance in place
to prevent bad config from being generated.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit a7141b85c8ded6f05edf51d5a61e063493fc85c7)

lib/command.c

index 3718c145940aef5c1c3aa6bd0251c94b2f59f1a8..e51609387b91dce2e02ad7cdcc27816725896d37 100644 (file)
@@ -430,11 +430,15 @@ static bool full_cli;
 /* This function write configuration of this host. */
 static int config_write_host(struct vty *vty)
 {
-       if (cmd_hostname_get())
-               vty_out(vty, "hostname %s\n", cmd_hostname_get());
+       const char *name;
 
-       if (cmd_domainname_get())
-               vty_out(vty, "domainname %s\n", cmd_domainname_get());
+       name = cmd_hostname_get();
+       if (name && name[0] != '\0')
+               vty_out(vty, "hostname %s\n", name);
+
+       name = cmd_domainname_get();
+       if (name && name[0] != '\0')
+               vty_out(vty, "domainname %s\n", name);
 
        /* The following are all configuration commands that are not sent to
         * watchfrr.  For instance watchfrr is hardcoded to log to syslog so