Fix compiler warning.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 27 Mar 2022 18:56:48 +0000 (20:56 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 27 Mar 2022 18:56:48 +0000 (20:56 +0200)
Quash a compiler warning by checking the result of snprintf() and
handling truncation.

src/tincctl.c

index a3978bc..0e7d083 100644 (file)
@@ -1894,7 +1894,11 @@ static int cmd_config(int argc, char *argv[]) {
        char filename[PATH_MAX];
 
        if(node) {
-               snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, node);
+               if((size_t)snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, node) >= sizeof(filename)) {
+                       fprintf(stderr, "Filename too long: %s" SLASH "%s\n", hosts_dir, node);
+                       free(node);
+                       return 1;
+               }
 
                if(node != line) {
                        free(node);