Skip to contentSkip to conversation

fsck.f2fs: do not print content beyond sb->version

PATCH Superseded Junling Zheng 2 participants 6 messages Jun 6, 2018 – Jun 8, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsck.f2fs: do not print content beyond sb->version

Currently, versions in f2fs_configuration have one more byte than those in sb, so versions in sb may not end with '\0', and then print_raw_sb_info() will print something beyond sb->version.

---
 fsck/mount.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fsck/mount.c +4 -1
index 0a30adb..9def919 100644
@@ -341,7 +341,10 @@ void print_raw_sb_info(struct f2fs_super_block *sb)
 	DISP_u32(sb, node_ino);
 	DISP_u32(sb, meta_ino);
 	DISP_u32(sb, cp_payload);
-	DISP("%s", sb, version);
+	if (sb->version[255] != '\0')
+		DISP("%-.256s", sb, version);
+	else
+		DISP("%s", sb, version);
 	printf("\n");
 }
 
Signature · 6 lines
2.17.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
#1 lore raw

Actually, I prefer to fix this bug by unifying the length of versions in f2fs_configuration and f2fs_super_block :)

Reference: https://sourceforge.net/p/linux-f2fs/mailman/message/35398537/

Thanks

Quoted 16 lines · Junling Zheng

Currently, versions in f2fs_configuration have one more byte than those in sb, so versions in sb may not end with '\0', and then print_raw_sb_info() will print something beyond sb->version.

---
 fsck/mount.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fsck/mount.c +0 -0
index 0a30adb..9def919 100644
@@ -341,7 +341,10 @@ void print_raw_sb_info(struct f2fs_super_block *sb)
 	DISP_u32(sb, node_ino);

fsck/mount.c void print_raw_sb_info(struct f2fs_super_block *sb) · line 350

Quoted 10 lines
fsck/mount.c +4 -1
 	DISP_u32(sb, meta_ino);
 	DISP_u32(sb, cp_payload);
-	DISP("%s", sb, version);
+	if (sb->version[255] != '\0')
+		DISP("%-.256s", sb, version);
+	else
+		DISP("%s", sb, version);
 	printf("\n");
 }
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#2 lore raw
In reply to Junling Zheng
Quoted 14 lines · Junling Zheng

Currently, versions in f2fs_configuration have one more byte than those in sb, so versions in sb may not end with '\0', and then print_raw_sb_info() will print something beyond sb->version.

---
 fsck/mount.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fsck/mount.c +0 -0
index 0a30adb..9def919 100644

fsck/mount.c void print_raw_sb_info(struct f2fs_super_block *sb) · line 347

Quoted 8 lines
fsck/mount.c +4 -1
@@ -341,7 +341,10 @@ void print_raw_sb_info(struct f2fs_super_block *sb)
 	DISP_u32(sb, node_ino);
 	DISP_u32(sb, meta_ino);
 	DISP_u32(sb, cp_payload);
-	DISP("%s", sb, version);
+	if (sb->version[255] != '\0')
+		DISP("%-.256s", sb, version);
+	else
+		DISP("%s", sb, version);

IMO, DISP("%-.256s", sb, version) is enough.

Thanks,

fsck/mount.c void print_raw_sb_info(struct f2fs_super_block *sb) · line 350

Quoted 4 lines
fsck/mount.c +0 -0
 	printf("\n");
 }
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#3 lore raw
Quoted 10 lines · Chao Yu
Quoted 9 lines · Junling Zheng

Currently, versions in f2fs_configuration have one more byte than those in sb, so versions in sb may not end with '\0', and then print_raw_sb_info() will print something beyond sb->version.

---
 fsck/mount.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 16 lines

fsck/mount.c void print_raw_sb_info(struct f2fs_super_block *sb) · line 347

Quoted 13 lines
fsck/mount.c +4 -1
index 0a30adb..9def919 100644
@@ -341,7 +341,10 @@ void print_raw_sb_info(struct f2fs_super_block *sb)
 	DISP_u32(sb, node_ino);
 	DISP_u32(sb, meta_ino);
 	DISP_u32(sb, cp_payload);
-	DISP("%s", sb, version);
+	if (sb->version[255] != '\0')
+		DISP("%-.256s", sb, version);
+	else
+		DISP("%s", sb, version);

IMO, DISP("%-.256s", sb, version) is enough.

Yeah, it works :)

Thanks,

Quoted 10 lines

Thanks,

fsck/mount.c void print_raw_sb_info(struct f2fs_super_block *sb) · line 350

Quoted 4 lines
fsck/mount.c +0 -0
 	printf("\n");
 }
 

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#4 lore raw

PATCH v2 1/1 fsck.f2fs: do not print content beyond sb->version

In reply to Junling Zheng

Currently, versions in f2fs_configuration have one more byte than those in sb, so versions in sb may not end with '\0', and then print_raw_sb_info() will print something beyond sb->version.

---
 fsck/mount.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsck/mount.c +1 -1
index 0a30adb..66b4a5d 100644
@@ -341,7 +341,7 @@ void print_raw_sb_info(struct f2fs_super_block *sb)
 	DISP_u32(sb, node_ino);
 	DISP_u32(sb, meta_ino);
 	DISP_u32(sb, cp_payload);
-	DISP("%s", sb, version);
+	DISP("%-.256s", sb, version);
 	printf("\n");
 }
 
Signature · 6 lines
2.17.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Reviewed-by on v2 1/1
#5 lore raw
Quoted 5 lines · Junling Zheng

Currently, versions in f2fs_configuration have one more byte than those in sb, so versions in sb may not end with '\0', and then print_raw_sb_info() will print something beyond sb->version.

Thanks,

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot