ext4: add filetype checking to ext4_mknod
authorKaho Ng <ngkaho1234@gmail.com>
Wed, 29 Jun 2016 21:30:28 +0000 (05:30 +0800)
committerKaho Ng <ngkaho1234@gmail.com>
Wed, 29 Jun 2016 21:40:08 +0000 (05:40 +0800)
src/ext4.c

index 0f2f07af9a879bc9904fc5078377cccb0d3332f9..7f10e11686d65232ad79813f50e5fcf1d4e4cd9a 100644 (file)
@@ -2448,9 +2448,23 @@ int ext4_mknod(const char *path, int filetype, uint32_t dev)
        if (mp->fs.read_only)
                return EROFS;
 
+       /*
+        * The filetype shouldn't be normal file, directory or
+        * unknown.
+        */
        if (filetype == EXT4_DE_UNKNOWN ||
            filetype == EXT4_DE_REG_FILE ||
-           filetype == EXT4_DE_DIR)
+           filetype == EXT4_DE_DIR ||
+           filetype == EXT4_DE_SYMLINK)
+               return EINVAL;
+
+       /*
+        * Nor should it be any bogus value.
+        */
+       if (filetype != EXT4_DE_CHRDEV &&
+           filetype != EXT4_DE_BLKDEV &&
+           filetype != EXT4_DE_FIFO &&
+           filetype != EXT4_DE_SOCK)
                return EINVAL;
 
        EXT4_MP_LOCK(mp);