tune2fs: Fix mount_opts handling

The extended options parsing for mount_opts was horribly buggy.
Invalid mount options that had an argument would get interpreted as an
extended mount options.  Fix this.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 7aacff3..0d1b751 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -80,6 +80,7 @@
 static int stride_set, stripe_width_set;
 static char *extended_cmd;
 static unsigned long new_inode_size;
+static char *ext_mount_opts;
 
 int journal_size, journal_flags;
 char *journal_device;
@@ -979,7 +980,7 @@
 				 "to %s (%d)\n"),
 			       arg, hash_alg);
 			ext2fs_mark_super_dirty(fs);
-		} else if (strcmp(token, "mount-options")) {
+		} else if (!strcmp(token, "mount_opts")) {
 			if (!arg) {
 				r_usage++;
 				continue;
@@ -989,8 +990,7 @@
 					"Extended mount options too long\n");
 				continue;
 			}
-			strcpy(fs->super->s_mount_opts, arg);
-			ext2fs_mark_super_dirty(fs);
+			ext_mount_opts = strdup(arg);
 		} else
 			r_usage++;
 	}
@@ -1000,9 +1000,10 @@
 			"and may take an argument which\n"
 			"\tis set off by an equals ('=') sign.\n\n"
 			"Valid extended options are:\n"
+			"\thash_alg=<hash algorithm>\n"
+			"\tmount_opts=<extended default mount options>\n"
 			"\tstride=<RAID per-disk chunk size in blocks>\n"
 			"\tstripe_width=<RAID stride*data disks in blocks>\n"
-			"\thash_alg=<hash algorithm>\n"
 			"\ttest_fs\n"
 			"\t^test_fs\n"));
 		free(buf);
@@ -1859,6 +1860,15 @@
 		ext2fs_mark_super_dirty(fs);
 		printf(_("Setting stripe width to %d\n"), stripe_width);
 	}
+	if (ext_mount_opts) {
+		strncpy(fs->super->s_mount_opts, ext_mount_opts,
+			sizeof(fs->super->s_mount_opts));
+		fs->super->s_mount_opts[sizeof(fs->super->s_mount_opts)-1] = 0;
+		ext2fs_mark_super_dirty(fs);
+		printf(_("Setting extended default mount options to '%s'\n"),
+		       ext_mount_opts);
+		free(ext_mount_opts);
+	}
 	free(device_name);
 	remove_error_table(&et_ext2_error_table);
 	return (ext2fs_close(fs) ? 1 : 0);