[PATCH] mkfs.ubifs: Fix runtime assertions when running without crypto
Henri Roosen
henriroosen at gmail.com
Mon Mar 8 12:59:18 GMT 2021
Running mkfs.ubifs which was build without crypto triggered the
following assertion:
mkfs.ubifs: ubifs-utils/mkfs.ubifs/fscrypt.h:166:
inherit_fscrypt_context: Assertion `0' failed.
A previous commit-cc4c5e295f54 ("mkfs.ubifs: Enable support for building
without crypto") added a check for an existing fscrypt context before calling
functions inherit_fscrypt_context() and free_fscrypt_context(),
however did not properly do this for each call to these functions.
Fixes: cc4c5e295f54 ("mkfs.ubifs: Enable support for building without crypto")
Signed-off-by: Henri Roosen <henri.roosen at ginzinger.com>
---
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
index 8211ada..c3a909c 100644
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -2092,7 +2092,8 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st,
if (S_ISDIR(dent_st.st_mode)) {
err = add_directory(name, inum, &dent_st, 1, new_fctx);
if (err) {
- free_fscrypt_context(new_fctx);
+ if (new_fctx)
+ free_fscrypt_context(new_fctx);
goto out_free;
}
nlink += 1;
@@ -2101,20 +2102,23 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st,
err = add_non_dir(name, &inum, 0, &type,
&dent_st, new_fctx);
if (err) {
- free_fscrypt_context(new_fctx);
+ if (new_fctx)
+ free_fscrypt_context(new_fctx);
goto out_free;
}
}
err = create_inum_attr(inum, name);
if (err) {
- free_fscrypt_context(new_fctx);
+ if (new_fctx)
+ free_fscrypt_context(new_fctx);
goto out_free;
}
err = add_dent_node(dir_inum, entry->d_name, inum, type, fctx);
if (err) {
- free_fscrypt_context(new_fctx);
+ if (new_fctx)
+ free_fscrypt_context(new_fctx);
goto out_free;
}
size += ALIGN(UBIFS_DENT_NODE_SZ + strlen(entry->d_name) + 1,
@@ -2158,12 +2162,14 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st,
name = make_path(dir_name, nh_elt->name);
inum = ++c->highest_inum;
- new_fctx = inherit_fscrypt_context(fctx);
+ if (fctx)
+ new_fctx = inherit_fscrypt_context(fctx);
if (S_ISDIR(nh_elt->mode)) {
err = add_directory(name, inum, &fake_st, 0, new_fctx);
if (err) {
- free_fscrypt_context(new_fctx);
+ if (new_fctx)
+ free_fscrypt_context(new_fctx);
goto out_free;
}
nlink += 1;
@@ -2172,20 +2178,23 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st,
err = add_non_dir(name, &inum, 0, &type,
&fake_st, new_fctx);
if (err) {
- free_fscrypt_context(new_fctx);
+ if (new_fctx)
+ free_fscrypt_context(new_fctx);
goto out_free;
}
}
err = create_inum_attr(inum, name);
if (err) {
- free_fscrypt_context(new_fctx);
+ if (new_fctx)
+ free_fscrypt_context(new_fctx);
goto out_free;
}
err = add_dent_node(dir_inum, nh_elt->name, inum, type, fctx);
if (err) {
- free_fscrypt_context(new_fctx);
+ if (new_fctx)
+ free_fscrypt_context(new_fctx);
goto out_free;
}
--
2.20.1
More information about the linux-mtd
mailing list