This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch andyp-sparse
in repository gfs2-utils.
commit 018c2b6a81d5c17a50fcb7d338c2248824fdd676
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed Apr 21 20:12:37 2021 +0100
libgfs2: Remove gfs2_ea_header_in
Update users to avoid storing cpu-endian data in an on-disk struct and
remove gfs2_ea_header_in(). Replace the gfs2_ea_header_print() function
with one that expects big-endian data and make it safer against buffer
overruns.
(There is no gfs2_ea_header_out() to remove.)
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/gfs2hex.c | 12 +++++++-----
gfs2/edit/savemeta.c | 15 +++++++++------
gfs2/libgfs2/libgfs2.h | 3 +--
gfs2/libgfs2/ondisk.c | 41 ++++++++++++++++++-----------------------
4 files changed, 35 insertions(+), 36 deletions(-)
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index b1fc1433..8fdc68a0 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -346,19 +346,21 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir)
static void do_eattr_extended(char *buf)
{
- struct gfs2_ea_header ea;
+ struct gfs2_ea_header *ea;
+ uint32_t rec_len = 0;
unsigned int x;
eol(0);
print_gfs2("Eattr Entries:");
eol(0);
- for (x = sizeof(struct gfs2_meta_header); x < sbd.bsize;
- x += ea.ea_rec_len)
+ for (x = sizeof(struct gfs2_meta_header); x < sbd.bsize; x += rec_len)
{
eol(0);
- gfs2_ea_header_in(&ea, buf + x);
- gfs2_ea_header_print(&ea, buf + x + sizeof(struct gfs2_ea_header));
+ buf += x;
+ ea = (struct gfs2_ea_header *)buf;
+ lgfs2_ea_header_print(ea);
+ rec_len = be32_to_cpu(ea->ea_rec_len);
}
}
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index e256fa26..e9401e4a 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -694,18 +694,20 @@ static char *check_read_block(int fd, uint64_t blk, uint64_t owner,
int *blktype
*/
static void save_ea_block(struct metafd *mfd, char *buf, uint64_t owner)
{
+ struct gfs2_ea_header *ea;
+ uint32_t rec_len = 0;
int e;
- struct gfs2_ea_header ea;
- for (e = sizeof(struct gfs2_meta_header); e < sbd.bsize; e += ea.ea_rec_len) {
+ for (e = sizeof(struct gfs2_meta_header); e < sbd.bsize; e += rec_len) {
uint64_t blk, *b;
int charoff, i;
- gfs2_ea_header_in(&ea, buf + e);
- for (i = 0; i < ea.ea_num_ptrs; i++) {
+ ea = (void *)(buf + e);
+ /* ea_num_ptrs and ea_name_len are u8 so no endianness worries */
+ for (i = 0; i < ea->ea_num_ptrs; i++) {
char *_buf;
- charoff = e + ea.ea_name_len +
+ charoff = e + ea->ea_name_len +
sizeof(struct gfs2_ea_header) +
sizeof(uint64_t) - 1;
charoff /= sizeof(uint64_t);
@@ -718,7 +720,8 @@ static void save_ea_block(struct metafd *mfd, char *buf, uint64_t
owner)
free(_buf);
}
}
- if (!ea.ea_rec_len)
+ rec_len = be32_to_cpu(ea->ea_rec_len);
+ if (rec_len == 0)
break;
}
}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 20cb11bf..acd98d23 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -713,7 +713,6 @@ extern void gfs2_dirent_in(struct gfs2_dirent *de, char *buf);
extern void gfs2_dirent_out(struct gfs2_dirent *de, char *buf);
extern void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf);
extern void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf);
-extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf);
extern void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf);
extern void gfs2_log_header_out(struct gfs2_log_header *lh, char *buf);
@@ -727,13 +726,13 @@ extern void gfs2_rgrp_print(const struct gfs2_rgrp *rg);
extern void gfs2_quota_print(const struct gfs2_quota *qu);
extern void gfs2_dinode_print(const struct gfs2_dinode *di);
extern void gfs2_leaf_print(const struct gfs2_leaf *lf);
-extern void gfs2_ea_header_print(const struct gfs2_ea_header *ea, char *name);
extern void gfs2_log_header_print(const struct gfs2_log_header *lh);
/* These expect on-disk data instead of native-endian structs */
extern void lgfs2_meta_header_print(void *mhp);
extern void lgfs2_log_descriptor_print(void *ldp);
extern void lgfs2_quota_change_print(void *qcp);
extern void lgfs2_statfs_change_print(void *scp);
+extern void lgfs2_ea_header_print(void *eap);
__END_DECLS
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index 8f28ca6e..a1ba73c3 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -25,6 +25,9 @@
#define printbe64(struct, member) do { \
print_it(" "#member, "%"PRIu64, "0x%"PRIx64,
be64_to_cpu(struct->member)); \
} while(0)
+#define print8(struct, member) do { \
+ print_it(" "#member, "%"PRIu8, "0x%"PRIx8,
struct->member); \
+ } while(0)
#define CPIN_08(s1, s2, member, count) {memcpy((s1->member), (s2->member),
(count));}
#define CPOUT_08(s1, s2, member, count) {memcpy((s2->member), (s1->member),
(count));}
@@ -466,31 +469,23 @@ void gfs2_leaf_print(const struct gfs2_leaf *lf)
pv(lf, lf_sec, "%"PRIu64, "0x%"PRIx64);
}
-void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf)
-{
- struct gfs2_ea_header *str = (struct gfs2_ea_header *)buf;
-
- CPIN_32(ea, str, ea_rec_len);
- CPIN_32(ea, str, ea_data_len);
- ea->ea_name_len = str->ea_name_len;
- ea->ea_type = str->ea_type;
- ea->ea_flags = str->ea_flags;
- ea->ea_num_ptrs = str->ea_num_ptrs;
-}
-
-void gfs2_ea_header_print(const struct gfs2_ea_header *ea, char *name)
+void lgfs2_ea_header_print(void *eap)
{
char buf[GFS2_EA_MAX_NAME_LEN + 1];
-
- pv(ea, ea_rec_len, "%"PRIu32, "0x%"PRIx32);
- pv(ea, ea_data_len, "%"PRIu32, "0x%"PRIx32);
- pv(ea, ea_name_len, "%"PRIu8, "0x%"PRIx8);
- pv(ea, ea_type, "%"PRIu8, "0x%"PRIx8);
- pv(ea, ea_flags, "%"PRIu8, "0x%"PRIx8);
- pv(ea, ea_num_ptrs, "%"PRIu8, "0x%"PRIx8);
-
- memset(buf, 0, GFS2_EA_MAX_NAME_LEN + 1);
- memcpy(buf, name, ea->ea_name_len);
+ struct gfs2_ea_header *ea = eap;
+ unsigned len = ea->ea_name_len;
+
+ printbe32(ea, ea_rec_len);
+ printbe32(ea, ea_data_len);
+ print8(ea, ea_name_len);
+ print8(ea, ea_type);
+ print8(ea, ea_flags);
+ print8(ea, ea_num_ptrs);
+
+ if (len > GFS2_EA_MAX_NAME_LEN)
+ len = GFS2_EA_MAX_NAME_LEN;
+ memcpy(buf, ea + 1, len);
+ buf[len] = '\0';
print_it(" name", "%s", NULL, buf);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.