]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Catch NULL during node path building
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 29 Oct 2025 22:56:22 +0000 (16:56 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 29 Oct 2025 22:56:22 +0000 (16:56 -0600)
Prevents a `strdup(NULL)`.

src/cache.c

index 33341f45d321ecc52a6160d3edc72d0c949b09ad..f469413be451bd8d3011a2a8e85fb9222431ad39 100644 (file)
@@ -1098,15 +1098,26 @@ refresh_success:
        return VV_CONTINUE;
 }
 
-/* Result needs free() */
+/*
+ * Note, RRDP can return NULL, because it hard-tracks its files.
+ * rsync doesn't. As long as the node exists, it will return a path,
+ * even if it doesn't point anywhere.
+ * Result needs free().
+ */
 static char *
 node2file(struct cache_node const *node, struct uri const *url)
 {
+       char const *file;
+
        if (node == NULL)
                return NULL;
-       return (node->rrdp)
-           ? /* RRDP  */ pstrdup(rrdp_file(node->rrdp, url))
-           : /* rsync */ path_join(node->path, strip_rsync_module(uri_str(url)));
+
+       if (node->rrdp) {
+               file = rrdp_file(node->rrdp, url);
+               return file ? pstrdup(file) : NULL;
+       } else { /* rsync */
+               return path_join(node->path, strip_rsync_module(uri_str(url)));
+       }
 }
 
 /* Result needs free() */