This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch RHEL7 in repository gfs2-utils.
commit 0fa27cdd64946c49823669e7ab77d8a06d9a00b9 Author: Andrew Price anprice@redhat.com Date: Wed Nov 9 18:27:12 2016 +0000
gfs2_edit: Fix unaligned access in restore_init()
Scanning this buffer byte-by-byte using casts results in a quick bus error on sparc64. Avoid this by using a memcpy. This function only runs once at the beginning of a restoremeta and in most cases the loop will only execute once so this adds very little overhead.
Reported-By: Valentin Vidic Valentin.Vidic@CARNet.hr Signed-off-by: Andrew Price anprice@redhat.com --- gfs2/edit/savemeta.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c index c9b51e9..ac2dd9f 100644 --- a/gfs2/edit/savemeta.c +++ b/gfs2/edit/savemeta.c @@ -924,8 +924,7 @@ static off_t restore_init(gzFile gzfd, struct savemeta_header *smh) size_t rs; char buf[256]; off_t startpos = 0; - struct saved_metablock *svb; - struct gfs2_meta_header *sbmh; + struct gfs2_meta_header sbmh;
err = read_header(gzfd, smh); if (err < 0) { @@ -943,14 +942,15 @@ static off_t restore_init(gzFile gzfd, struct savemeta_header *smh) exit(1); } /* Scan for the beginning of the file body. Required to support old formats(?). */ - for (i = 0; i < (256 - sizeof(*svb) - sizeof(*sbmh)); i++) { - svb = (struct saved_metablock *)&buf[i]; - sbmh = (struct gfs2_meta_header *)svb->buf; - if (sbmh->mh_magic == cpu_to_be32(GFS2_MAGIC) && - sbmh->mh_type == cpu_to_be32(GFS2_METATYPE_SB)) + for (i = 0; i < (256 - sizeof(struct saved_metablock) - sizeof(sbmh)); i++) { + off_t off = i + sizeof(struct saved_metablock); + + memcpy(&sbmh, &buf[off], sizeof(sbmh)); + if (sbmh.mh_magic == cpu_to_be32(GFS2_MAGIC) && + sbmh.mh_type == cpu_to_be32(GFS2_METATYPE_SB)) break; } - if (i == (sizeof(buf) - sizeof(*svb) - sizeof(*sbmh))) + if (i == (sizeof(buf) - sizeof(struct saved_metablock) - sizeof(sbmh))) i = 0; return startpos + i; /* File offset of saved sb */ }
cluster-commits@lists.fedorahosted.org