Skip to content

Commit be076fd

Browse files
Dan Carpenterrichardweinberger
authored andcommitted
ubifs: fix snprintf() checking
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: ae380ce ("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>
1 parent a2c2a62 commit be076fd

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/mtd/ubi/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
511511

512512
n = snprintf(d->dfs_dir_name, UBI_DFS_DIR_LEN + 1, UBI_DFS_DIR_NAME,
513513
ubi->ubi_num);
514-
if (n == UBI_DFS_DIR_LEN) {
514+
if (n > UBI_DFS_DIR_LEN) {
515515
/* The array size is too small */
516516
return -EINVAL;
517517
}

fs/ubifs/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2824,7 +2824,7 @@ void dbg_debugfs_init_fs(struct ubifs_info *c)
28242824

28252825
n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME,
28262826
c->vi.ubi_num, c->vi.vol_id);
2827-
if (n == UBIFS_DFS_DIR_LEN) {
2827+
if (n > UBIFS_DFS_DIR_LEN) {
28282828
/* The array size is too small */
28292829
return;
28302830
}

0 commit comments

Comments
 (0)