Skip to contentSkip to conversation

ubifs: fix snprintf() length check

PATCH New Dan Carpenter 1 participant 1 message Nov 9, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubifs: fix snprintf() length check

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")
---
 fs/ubifs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/sysfs.c +1 -1
index 0eb3d7d12450..7acc5a74e5fa 100644
@@ -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;
Signature · 1 line
2.20.1