aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2020-01-25 03:07:05 -0500
committerTheodore Ts'o <tytso@mit.edu>2020-01-25 03:07:05 -0500
commit0b47dde9fd8859d8962b601e6cc8d4d705d303ab (patch)
tree5a647262b818f01df362dc40188697bbb372d966
parenta320a1c6a0aa57d91b3471a7a65eef2688960568 (diff)
parentbc56227376223c02b16703691fd0de6929a1036b (diff)
downloade2fsprogs-0b47dde9fd8859d8962b601e6cc8d4d705d303ab.tar.gz
Merge branch 'maint' into next
-rw-r--r--debugfs/debugfs.c6
-rw-r--r--e2fsck/unix.c17
-rw-r--r--e2fsck/util.c6
-rw-r--r--lib/blkid/probe.c2
-rw-r--r--lib/e2p/ls.c39
-rw-r--r--lib/ext2fs/ext2_fs.h17
-rw-r--r--lib/support/plausible.c12
-rw-r--r--misc/dumpe2fs.c12
-rw-r--r--misc/e2label.c2
-rw-r--r--misc/findsuper.c5
-rw-r--r--misc/mke2fs.c6
-rw-r--r--misc/tune2fs.c3
-rw-r--r--misc/util.c5
-rw-r--r--tests/filter.sed1
14 files changed, 66 insertions, 67 deletions
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 9b7014559..9e22c68fc 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -2446,8 +2446,10 @@ void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[],
fprintf(stdout, "check_interval: %d\n", mmp_s->mmp_check_interval);
fprintf(stdout, "sequence: %08x\n", mmp_s->mmp_seq);
fprintf(stdout, "time: %lld -- %s", mmp_s->mmp_time, ctime(&t));
- fprintf(stdout, "node_name: %s\n", mmp_s->mmp_nodename);
- fprintf(stdout, "device_name: %s\n", mmp_s->mmp_bdevname);
+ fprintf(stdout, "node_name: %.*s\n",
+ EXT2_LEN_STR(mmp_s->mmp_nodename));
+ fprintf(stdout, "device_name: %.*s\n",
+ EXT2_LEN_STR(mmp_s->mmp_bdevname));
fprintf(stdout, "magic: 0x%x\n", mmp_s->mmp_magic);
fprintf(stdout, "checksum: 0x%08x\n", mmp_s->mmp_checksum);
}
diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index b3ef0f22b..b144c385a 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -1697,11 +1697,10 @@ failure:
* Set the device name, which is used whenever we print error
* or informational messages to the user.
*/
- if (ctx->device_name == 0 &&
- (sb->s_volume_name[0] != 0)) {
+ if (ctx->device_name == 0 && sb->s_volume_name[0])
ctx->device_name = string_copy(ctx, sb->s_volume_name,
sizeof(sb->s_volume_name));
- }
+
if (ctx->device_name == 0)
ctx->device_name = string_copy(ctx, ctx->filesystem_name, 0);
for (cp = ctx->device_name; *cp; cp++)
@@ -1709,19 +1708,19 @@ failure:
*cp = '_';
if (ctx->problem_logf) {
- char buf[48];
fprintf(ctx->problem_logf, "<filesystem dev=\"%s\"",
ctx->filesystem_name);
if (!uuid_is_null(sb->s_uuid)) {
+ char buf[48];
+
uuid_unparse(sb->s_uuid, buf);
fprintf(ctx->problem_logf, " uuid=\"%s\"", buf);
}
- if (sb->s_volume_name[0]) {
- memset(buf, 0, sizeof(buf));
- strncpy(buf, sb->s_volume_name, sizeof(buf));
- fprintf(ctx->problem_logf, " label=\"%s\"", buf);
- }
+ if (sb->s_volume_name[0])
+ fprintf(ctx->problem_logf, " label=\"%.*s\"",
+ EXT2_LEN_STR(sb->s_volume_name));
+
fputs("/>\n", ctx->problem_logf);
}
diff --git a/e2fsck/util.c b/e2fsck/util.c
index db6a1cc11..314c98947 100644
--- a/e2fsck/util.c
+++ b/e2fsck/util.c
@@ -777,8 +777,10 @@ void dump_mmp_msg(struct mmp_struct *mmp, const char *fmt, ...)
printf(" mmp_sequence: %08x\n", mmp->mmp_seq);
printf(" mmp_update_date: %s", ctime(&t));
printf(" mmp_update_time: %lld\n", mmp->mmp_time);
- printf(" mmp_node_name: %s\n", mmp->mmp_nodename);
- printf(" mmp_device_name: %s\n", mmp->mmp_bdevname);
+ printf(" mmp_node_name: %.*s\n",
+ EXT2_LEN_STR(mmp->mmp_nodename));
+ printf(" mmp_device_name: %.*s\n",
+ EXT2_LEN_STR(mmp->mmp_bdevname));
}
}
diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c
index d72014489..f8687cdeb 100644
--- a/lib/blkid/probe.c
+++ b/lib/blkid/probe.c
@@ -144,7 +144,7 @@ static void get_ext2_info(blkid_dev dev, struct blkid_magic *id,
blkid_le32(es->s_feature_incompat),
blkid_le32(es->s_feature_ro_compat)));
- if (strlen(es->s_volume_name))
+ if (es->s_volume_name[0])
label = es->s_volume_name;
blkid_set_tag(dev, "LABEL", label, sizeof(es->s_volume_name));
diff --git a/lib/e2p/ls.c b/lib/e2p/ls.c
index 5a4461781..152109995 100644
--- a/lib/e2p/ls.c
+++ b/lib/e2p/ls.c
@@ -224,7 +224,7 @@ static const char *quota_type2prefix(enum quota_type qtype)
void list_super2(struct ext2_super_block * sb, FILE *f)
{
int inode_blocks_per_group;
- char buf[80], *str;
+ char *str;
time_t tm;
enum quota_type qtype;
@@ -232,18 +232,16 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
EXT2_INODE_SIZE(sb)) +
EXT2_BLOCK_SIZE(sb) - 1) /
EXT2_BLOCK_SIZE(sb));
- if (sb->s_volume_name[0]) {
- memset(buf, 0, sizeof(buf));
- strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name));
- } else
- strcpy(buf, "<none>");
- fprintf(f, "Filesystem volume name: %s\n", buf);
- if (sb->s_last_mounted[0]) {
- memset(buf, 0, sizeof(buf));
- strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted));
- } else
- strcpy(buf, "<not available>");
- fprintf(f, "Last mounted on: %s\n", buf);
+ if (sb->s_volume_name[0])
+ fprintf(f, "Filesystem volume name: %.*s\n",
+ EXT2_LEN_STR(sb->s_volume_name));
+ else
+ fprintf(f, "Filesystem volume name: <none>\n");
+ if (sb->s_last_mounted[0])
+ fprintf(f, "Last mounted on: %.*s\n",
+ EXT2_LEN_STR(sb->s_last_mounted));
+ else
+ fprintf(f, "Last mounted on: <not available>\n");
fprintf(f, "Filesystem UUID: %s\n", e2p_uuid2str(sb->s_uuid));
fprintf(f, "Filesystem magic number: 0x%04X\n", sb->s_magic);
fprintf(f, "Filesystem revision #: %d", sb->s_rev_level);
@@ -259,7 +257,8 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
print_super_flags(sb, f);
print_mntopts(sb, f);
if (sb->s_mount_opts[0])
- fprintf(f, "Mount options: %s\n", sb->s_mount_opts);
+ fprintf(f, "Mount options: %.*s\n",
+ EXT2_LEN_STR(sb->s_mount_opts));
fprintf(f, "Filesystem state: ");
print_fs_state (f, sb->s_state);
fprintf(f, "\n");
@@ -419,10 +418,8 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
if (sb->s_first_error_time) {
tm = sb->s_first_error_time;
fprintf(f, "First error time: %s", ctime(&tm));
- memset(buf, 0, sizeof(buf));
- strncpy(buf, (char *)sb->s_first_error_func,
- sizeof(sb->s_first_error_func));
- fprintf(f, "First error function: %s\n", buf);
+ fprintf(f, "First error function: %.*s\n",
+ EXT2_LEN_STR(sb->s_first_error_func));
fprintf(f, "First error line #: %u\n",
sb->s_first_error_line);
fprintf(f, "First error inode #: %u\n",
@@ -433,10 +430,8 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
if (sb->s_last_error_time) {
tm = sb->s_last_error_time;
fprintf(f, "Last error time: %s", ctime(&tm));
- memset(buf, 0, sizeof(buf));
- strncpy(buf, (char *)sb->s_last_error_func,
- sizeof(sb->s_last_error_func));
- fprintf(f, "Last error function: %s\n", buf);
+ fprintf(f, "Last error function: %.*s\n",
+ EXT2_LEN_STR(sb->s_last_error_func));
fprintf(f, "Last error line #: %u\n",
sb->s_last_error_line);
fprintf(f, "Last error inode #: %u\n",
diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
index 3165b3895..6fe5cab8b 100644
--- a/lib/ext2fs/ext2_fs.h
+++ b/lib/ext2fs/ext2_fs.h
@@ -682,8 +682,8 @@ struct ext2_super_block {
/*060*/ __u32 s_feature_incompat; /* incompatible feature set */
__u32 s_feature_ro_compat; /* readonly-compatible feature set */
/*068*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
-/*078*/ char s_volume_name[EXT2_LABEL_LEN]; /* volume name */
-/*088*/ char s_last_mounted[64]; /* directory where last mounted */
+/*078*/ __u8 s_volume_name[EXT2_LABEL_LEN]; /* volume name, no NUL? */
+/*088*/ __u8 s_last_mounted[64]; /* directory last mounted on, no NUL? */
/*0c8*/ __u32 s_algorithm_usage_bitmap; /* For compression */
/*
* Performance hints. Directory preallocation should only
@@ -731,15 +731,15 @@ struct ext2_super_block {
__u32 s_first_error_time; /* first time an error happened */
__u32 s_first_error_ino; /* inode involved in first error */
/*1a0*/ __u64 s_first_error_block; /* block involved in first error */
- __u8 s_first_error_func[32]; /* function where the error happened */
+ __u8 s_first_error_func[32]; /* function where error hit, no NUL? */
/*1c8*/ __u32 s_first_error_line; /* line number where error happened */
__u32 s_last_error_time; /* most recent time of an error */
/*1d0*/ __u32 s_last_error_ino; /* inode involved in last error */
__u32 s_last_error_line; /* line number where error happened */
__u64 s_last_error_block; /* block involved of last error */
-/*1e0*/ __u8 s_last_error_func[32]; /* function where the error happened */
+/*1e0*/ __u8 s_last_error_func[32]; /* function where error hit, no NUL? */
#define EXT4_S_ERR_END ext4_offsetof(struct ext2_super_block, s_mount_opts)
-/*200*/ __u8 s_mount_opts[64];
+/*200*/ __u8 s_mount_opts[64]; /* default mount options, no NUL? */
/*240*/ __u32 s_usr_quota_inum; /* inode number of user quota file */
__u32 s_grp_quota_inum; /* inode number of group quota file */
__u32 s_overhead_blocks; /* overhead blocks/clusters in fs */
@@ -763,6 +763,7 @@ struct ext2_super_block {
};
#define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START)
+#define EXT2_LEN_STR(buf) (int)sizeof(buf), (char *)buf
/*
* Codes for operating systems
@@ -1098,9 +1099,9 @@ struct ext2_dir_entry_tail {
struct mmp_struct {
__u32 mmp_magic; /* Magic number for MMP */
__u32 mmp_seq; /* Sequence no. updated periodically */
- __u64 mmp_time; /* Time last updated */
- char mmp_nodename[64]; /* Node which last updated MMP block */
- char mmp_bdevname[32]; /* Bdev which last updated MMP block */
+ __u64 mmp_time; /* Time last updated (seconds) */
+ __u8 mmp_nodename[64]; /* Node updating MMP block, no NUL? */
+ __u8 mmp_bdevname[32]; /* Bdev updating MMP block, no NUL? */
__u16 mmp_check_interval; /* Changed mmp_check_interval */
__u16 mmp_pad1;
__u32 mmp_pad2[226];
diff --git a/lib/support/plausible.c b/lib/support/plausible.c
index a7268980e..024f205e8 100644
--- a/lib/support/plausible.c
+++ b/lib/support/plausible.c
@@ -101,7 +101,6 @@ static void print_ext2_info(const char *device)
ext2_filsys fs;
errcode_t retval;
time_t tm;
- char buf[80];
retval = ext2fs_open2(device, 0, EXT2_FLAG_64BITS, 0, 0,
unix_io_manager, &fs);
@@ -111,13 +110,10 @@ static void print_ext2_info(const char *device)
if (sb->s_mtime) {
tm = sb->s_mtime;
- if (sb->s_last_mounted[0]) {
- memset(buf, 0, sizeof(buf));
- strncpy(buf, sb->s_last_mounted,
- sizeof(sb->s_last_mounted));
- printf(_("\tlast mounted on %s on %s"), buf,
- ctime(&tm));
- } else
+ if (sb->s_last_mounted[0])
+ printf(_("\tlast mounted on %.*s on %s"),
+ EXT2_LEN_STR(sb->s_last_mounted), ctime(&tm));
+ else
printf(_("\tlast mounted on %s"), ctime(&tm));
} else if (sb->s_mkfs_time) {
tm = sb->s_mkfs_time;
diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index 9a6f586ec..5c955a96d 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -439,8 +439,10 @@ static int check_mmp(ext2_filsys fs)
time_t mmp_time = mmp->mmp_time;
fprintf(stderr,
- "%s: MMP last updated by '%s' on %s",
- program_name, mmp->mmp_nodename,
+ "%s: MMP update by '%.*s%.*s' at %s",
+ program_name,
+ EXT2_LEN_STR(mmp->mmp_nodename),
+ EXT2_LEN_STR(mmp->mmp_bdevname),
ctime(&mmp_time));
}
retval = 1;
@@ -489,8 +491,10 @@ static void print_mmp_block(ext2_filsys fs)
printf(" mmp_sequence: %#08x\n", mmp->mmp_seq);
printf(" mmp_update_date: %s", ctime(&mmp_time));
printf(" mmp_update_time: %lld\n", mmp->mmp_time);
- printf(" mmp_node_name: %s\n", mmp->mmp_nodename);
- printf(" mmp_device_name: %s\n", mmp->mmp_bdevname);
+ printf(" mmp_node_name: %.*s\n",
+ EXT2_LEN_STR(mmp->mmp_nodename));
+ printf(" mmp_device_name: %.*s\n",
+ EXT2_LEN_STR(mmp->mmp_bdevname));
}
static void parse_extended_opts(const char *opts, blk64_t *superblock,
diff --git a/misc/e2label.c b/misc/e2label.c
index 526a62c35..910ccc772 100644
--- a/misc/e2label.c
+++ b/misc/e2label.c
@@ -81,7 +81,7 @@ static void print_label (char *dev)
char label[VOLNAMSZ+1];
open_e2fs (dev, O_RDONLY);
- strncpy(label, sb.s_volume_name, VOLNAMSZ);
+ snprintf(label, sizeof(label), "%.*s", EXT2_LEN_STR(sb.s_volume_name));
label[VOLNAMSZ] = 0;
printf("%s\n", label);
}
diff --git a/misc/findsuper.c b/misc/findsuper.c
index ff20b9885..765295c3b 100644
--- a/misc/findsuper.c
+++ b/misc/findsuper.c
@@ -251,7 +251,7 @@ int main(int argc, char *argv[])
sb_offset = 0;
if (jnl_copy && !print_jnl_copies)
continue;
- printf("\r%11Lu %11Lu%s %11Lu%s %9u %5Lu %4u%s %s %02x%02x%02x%02x %s\n",
+ printf("\r%11Lu %11Lu%s %11Lu%s %9u %5Lu %4u%s %s %02x%02x%02x%02x %.*s\n",
sk, sk - ext2.s_block_group_nr * grpsize - sb_offset,
jnl_copy ? "*":" ",
sk + ext2fs_blocks_count(&ext2) * bsize -
@@ -259,7 +259,8 @@ int main(int argc, char *argv[])
jnl_copy ? "*" : " ", ext2fs_blocks_count(&ext2), bsize,
ext2.s_block_group_nr, jnl_copy ? "*" : " ", s,
ext2.s_uuid[0], ext2.s_uuid[1],
- ext2.s_uuid[2], ext2.s_uuid[3], ext2.s_volume_name);
+ ext2.s_uuid[2], ext2.s_uuid[3],
+ EXT2_LEN_STR(ext2.s_volume_name));
}
printf(_("\n%11Lu: finished with errno %d\n"), sk, errno);
close(fd);
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index be38d2c4f..dc76a03b6 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -655,7 +655,6 @@ write_superblock:
static void show_stats(ext2_filsys fs)
{
struct ext2_super_block *s = fs->super;
- char buf[80];
char *os;
blk64_t group_block;
dgrp_t i;
@@ -673,9 +672,8 @@ static void show_stats(ext2_filsys fs)
fprintf(stderr, _("warning: %llu blocks unused.\n\n"),
ext2fs_blocks_count(&fs_param) - ext2fs_blocks_count(s));
- memset(buf, 0, sizeof(buf));
- strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
- printf(_("Filesystem label=%s\n"), buf);
+ printf(_("Filesystem label=%.*s\n"), EXT2_LEN_STR(s->s_volume_name));
+
os = e2p_os2string(fs->super->s_creator_os);
if (os)
printf(_("OS type: %s\n"), os);
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index a0448f63d..dd5d40aed 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -2990,8 +2990,7 @@ retry_open:
if (print_label) {
/* For e2label emulation */
- printf("%.*s\n", (int) sizeof(sb->s_volume_name),
- sb->s_volume_name);
+ printf("%.*s\n", EXT2_LEN_STR(sb->s_volume_name));
remove_error_table(&et_ext2_error_table);
goto closefs;
}
diff --git a/misc/util.c b/misc/util.c
index 779915893..dcd2f0a78 100644
--- a/misc/util.c
+++ b/misc/util.c
@@ -288,7 +288,8 @@ void dump_mmp_msg(struct mmp_struct *mmp, const char *msg)
if (mmp) {
time_t t = mmp->mmp_time;
- printf("MMP error info: last update: %s node: %s device: %s\n",
- ctime(&t), mmp->mmp_nodename, mmp->mmp_bdevname);
+ printf("MMP error info: node: %.*s, device: %.*s, updated: %s",
+ EXT2_LEN_STR(mmp->mmp_nodename),
+ EXT2_LEN_STR(mmp->mmp_bdevname), ctime(&t));
}
}
diff --git a/tests/filter.sed b/tests/filter.sed
index f37986ce1..796186e75 100644
--- a/tests/filter.sed
+++ b/tests/filter.sed
@@ -37,3 +37,4 @@ s/mmp_node_name: .*/mmp_node_name: test_node/
s/mmp_update_date: .*/mmp_update_date: test date/
s/mmp_update_time: .*/mmp_update_time: test_time/
s/MMP last updated by '.*' on .*/MMP last updated by 'test_node' on test date/
+s/MMP update by '.*' at .*/MMP last updated by 'test_node' on test date/