]> www.infradead.org Git - mtd-utils.git/commitdiff
mkfs.ubifs: Make sure we catch nodes that should or should not have name
authorRichard Weinberger <richard@nod.at>
Thu, 18 Oct 2018 14:36:54 +0000 (16:36 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 1 Nov 2018 11:39:37 +0000 (12:39 +0100)
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/mkfs.ubifs/key.h
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c

index c18e35e8f0a39f742c426f53d761e36617a0514c..2de530b813a20d382c1aca83e239fb9959b54a9f 100644 (file)
@@ -209,4 +209,14 @@ static inline int keys_cmp(const union ubifs_key *key1,
        return 0;
 }
 
+/**
+ * key_type - get key type.
+ * @c: UBIFS file-system description object
+ * @key: key to get type of
+ */
+static inline int key_type(const union ubifs_key *key)
+{
+       return key->u32[1] >> UBIFS_S_KEY_BLOCK_BITS;
+}
+
 #endif /* !__UBIFS_KEY_H__ */
index b402945924acce5e4a0a13b546c0a48f2a5a09c6..8aba668f8e28afdb08958e46103a62a3bb3b34f1 100644 (file)
@@ -1161,6 +1161,14 @@ static int add_node(union ubifs_key *key, char *name, int name_len, void *node,
 {
        int err, lnum, offs;
 
+       if (key_type(key) == UBIFS_DENT_KEY || key_type(key) == UBIFS_XENT_KEY) {
+               if (!name)
+                       return err_msg("Directory entry or xattr without name!");
+       } else {
+               if (name)
+                       return err_msg("Name given for non dir/xattr node!");
+       }
+
        prepare_node(node, len);
 
        err = reserve_space(len, &lnum, &offs);