Skip to contentSkip to conversation

tune2fs: exit directly when fs freed in ext2fs_run_ext3_journal

PATCH Applied Li Jinlin 2 participants 3 messages Sep 16, 2022 – Oct 20, 2022

lore
Share & tools
lore

Li Jinlin

author
#0 lore raw

PATCH 1/1 tune2fs: exit directly when fs freed in ext2fs_run_ext3_journal

In ext2fs_run_ext3_journal(), fs will be free and reallocate. But reallocating by ext2fs_open() may fail in some cases, such as device being offline at the same time. In these cases, goto closefs will cause segfault, fix it by exiting directly.

---
 misc/tune2fs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
misc/tune2fs.c +5 -2
index 088f87e5..ee57dc7c 100644
@@ -3344,8 +3344,11 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
 			com_err("tune2fs", retval,
 				"while recovering journal.\n");
 			printf(_("Please run e2fsck -fy %s.\n"), argv[1]);
-			rc = 1;
-			goto closefs;
+			if (fs) {
+				rc = 1;
+				goto closefs;
+			}
+			exit(1);
 		}
 		sb = fs->super;
 	}
Signature · 1 line
2.23.0
#2 lore raw
In reply to Li Jinlin
Quoted 6 lines · Li Jinlin

In ext2fs_run_ext3_journal(), fs will be free and reallocate. But reallocating by ext2fs_open() may fail in some cases, such as device being offline at the same time. In these cases, goto closefs will cause segfault, fix it by exiting directly.

Thanks, applied, although I simplified the patch a little:

@@ -3106,6 +3106,8 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"

                        com_err("tune2fs", retval,
                                "while recovering journal.\n");
                        printf(_("Please run e2fsck -fy %s.\n"), argv[1]);
+                       if (!fs)
+                               exit(1);
                        rc = 1;
                        goto closefs;
                }

					- Ted