ubifs: fix snprintf() checking
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 11 May 2021 07:12:00 +0000 (10:12 +0300)
committerRichard Weinberger <richard@nod.at>
Fri, 18 Jun 2021 20:04:47 +0000 (22:04 +0200)
The snprintf() function returns the number of characters (not
counting the NUL terminator) that it would have printed if we
had space.

This buffer has UBIFS_DFS_DIR_LEN characters plus one extra for
the terminator.  Printing UBIFS_DFS_DIR_LEN is okay but anything
higher will result in truncation.  Thus the comparison needs to be
change from == to >.

These strings are compile time constants so this patch doesn't
affect runtime.

Fixes: ae380ce04731 ("UBIFS: lessen the size of debugging info data structure")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Alexander Dahl <ada@thorsis.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
drivers/mtd/ubi/debug.c
fs/ubifs/debug.c

index ac2bdba..3c0c8ec 100644 (file)
@@ -511,7 +511,7 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
 
        n = snprintf(d->dfs_dir_name, UBI_DFS_DIR_LEN + 1, UBI_DFS_DIR_NAME,
                     ubi->ubi_num);
-       if (n == UBI_DFS_DIR_LEN) {
+       if (n > UBI_DFS_DIR_LEN) {
                /* The array size is too small */
                return -EINVAL;
        }
index 1bbb9fe..fc718f6 100644 (file)
@@ -2824,7 +2824,7 @@ void dbg_debugfs_init_fs(struct ubifs_info *c)
 
        n = snprintf(d->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 */
                return;
        }