ubifs: fix snprintf() length check
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 9 Nov 2021 11:50:51 +0000 (14:50 +0300)
committerRichard Weinberger <richard@nod.at>
Thu, 23 Dec 2021 21:08:19 +0000 (22:08 +0100)
The snprintf() function returns the number of bytes (not including the
NUL terminator) which would have been printed if there were enough
space.  So it can be greater than UBIFS_DFS_DIR_LEN.  And actually if
it equals UBIFS_DFS_DIR_LEN then that's okay so this check is too
strict.

Fixes: 9a620291fc01 ("ubifs: Export filesystem error counters")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/sysfs.c

index 0eb3d7d12450c47729363486dc45df2488ed5524..7acc5a74e5fa7d7bd72c5ac1646c3cbc8ac8316c 100644 (file)
@@ -100,7 +100,7 @@ int ubifs_sysfs_register(struct ubifs_info *c)
        n = snprintf(dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME,
                     c->vi.ubi_num, c->vi.vol_id);
 
-       if (n == UBIFS_DFS_DIR_LEN) {
+       if (n > UBIFS_DFS_DIR_LEN) {
                /* The array size is too small */
                ret = -EINVAL;
                goto out_free;