From a96f786a6fdd0d2935fae03c087145efc42a088f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sj=C3=B6lund?= Date: Mon, 25 Mar 2024 07:37:21 +0100 Subject: [PATCH 1/4] mountcomposefs: Handle empty basedir option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fail with an error message if any of the basedir option paths is an empty string. Signed-off-by: Erik Sjölund --- tools/mountcomposefs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/mountcomposefs.c b/tools/mountcomposefs.c index 29894cb..1e01b4f 100644 --- a/tools/mountcomposefs.c +++ b/tools/mountcomposefs.c @@ -216,10 +216,12 @@ int main(int argc, char **argv) if (options.objdirs == NULL) errx(EXIT_FAILURE, "Out of memory\n"); - for (i = 0, str = (char *)opt_basedir;; i++, str = NULL) { + for (i = 0, str = (char *)opt_basedir; i < options.n_objdirs; + i++, str = NULL) { token = strtok_r(str, ":", &saveptr); if (token == NULL) - break; + errx(EXIT_FAILURE, + "Value for basedir option has incorrect format\n"); options.objdirs[i] = token; } } From 09ca74022e80675be4d7d9285d1b658cc792bcfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sj=C3=B6lund?= Date: Mon, 25 Mar 2024 07:45:56 +0100 Subject: [PATCH 2/4] writer: Set errno for unknown format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Erik Sjölund --- libcomposefs/lcfs-writer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libcomposefs/lcfs-writer.c b/libcomposefs/lcfs-writer.c index 0519a55..31006f5 100644 --- a/libcomposefs/lcfs-writer.c +++ b/libcomposefs/lcfs-writer.c @@ -85,6 +85,7 @@ static struct lcfs_ctx_s *lcfs_new_ctx(struct lcfs_node_s *root, break; default: + errno = EINVAL; ret = NULL; } @@ -101,6 +102,7 @@ static struct lcfs_ctx_s *lcfs_new_ctx(struct lcfs_node_s *root, ret->fsverity_ctx = lcfs_fsverity_context_new(); if (ret->fsverity_ctx == NULL) { lcfs_close(ret); + errno = ENOMEM; return NULL; } } @@ -377,7 +379,6 @@ int lcfs_write_to(struct lcfs_node_s *root, struct lcfs_write_options_s *options ctx = lcfs_new_ctx(root, options); if (ctx == NULL) { - errno = ENOMEM; return -1; } From 456d618aa79fb883908bc2d4f36e20c261028ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sj=C3=B6lund?= Date: Mon, 25 Mar 2024 07:39:32 +0100 Subject: [PATCH 3/4] erofs: Add missing free() and lcfs_node_unref() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Erik Sjölund --- libcomposefs/lcfs-writer-erofs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libcomposefs/lcfs-writer-erofs.c b/libcomposefs/lcfs-writer-erofs.c index 46817ec..e5e81aa 100644 --- a/libcomposefs/lcfs-writer-erofs.c +++ b/libcomposefs/lcfs-writer-erofs.c @@ -347,16 +347,17 @@ static int compute_erofs_shared_xattrs(struct lcfs_ctx_s *ctx) ent = hash_lookup(xattr_hash, &hkey); if (ent == NULL) { - struct hasher_xattr_s *new_ent = + cleanup_free struct hasher_xattr_s *new_ent = calloc(1, sizeof(struct hasher_xattr_s)); if (new_ent == NULL) { goto fail; } new_ent->xattr = &node->xattrs[i]; ent = hash_insert(xattr_hash, new_ent); - if (ent == NULL) { + if (ent == NULL) goto fail; - } + assert(ent == new_ent); /* Due to result from previously run hash_lookup() */ + new_ent = NULL; } ent->count++; } @@ -1598,7 +1599,7 @@ static struct lcfs_node_s *lcfs_build_node_from_image(struct lcfs_image_data *da bool tailpacked; size_t xattr_size; struct hasher_node_s ht_entry = { nid }; - struct hasher_node_s *new_ht_entry; + cleanup_free struct hasher_node_s *new_ht_entry = NULL; struct hasher_node_s *existing; uint64_t n_blocks; uint64_t last_oob_block; @@ -1630,9 +1631,11 @@ static struct lcfs_node_s *lcfs_build_node_from_image(struct lcfs_image_data *da new_ht_entry->nid = nid; new_ht_entry->node = node; if (hash_insert(data->node_hash, new_ht_entry) == NULL) { + lcfs_node_unref(node); errno = ENOMEM; return NULL; } + new_ht_entry = NULL; if (erofs_inode_is_compact(cino)) { const struct erofs_inode_compact *c = &cino->compact; From a880713abbba231c798b676142ab3ea3e723536d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sj=C3=B6lund?= Date: Mon, 25 Mar 2024 07:42:13 +0100 Subject: [PATCH 4/4] mkcomposefs: Add missing free() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Erik Sjölund --- tools/mkcomposefs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/mkcomposefs.c b/tools/mkcomposefs.c index 7468603..a5074e3 100644 --- a/tools/mkcomposefs.c +++ b/tools/mkcomposefs.c @@ -117,7 +117,7 @@ static char *unescape_string(const char *escaped, size_t escaped_size, size_t *unescaped_size, char **err) { const char *escaped_end = escaped + escaped_size; - char *res = malloc(escaped_size + 1); + cleanup_free char *res = malloc(escaped_size + 1); if (res == NULL) oom(); char *out = res; @@ -182,7 +182,7 @@ static char *unescape_string(const char *escaped, size_t escaped_size, *out = 0; /* Null terminate */ - return res; + return steal_pointer(&res); } static char *unescape_optional_string(const char *escaped, size_t escaped_size,