From d7ac5d7226c71d53240961338fcbcb5d87976244 Mon Sep 17 00:00:00 2001 From: liyuan Date: Thu, 19 Oct 2023 23:21:17 +0800 Subject: [PATCH] backport libgfs2: Fix pointer cast byte order issue --- ...s2-Fix-pointer-cast-byte-order-issue.patch | 52 +++++++++++++++++++ gfs2-utils.spec | 7 ++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 0001-libgfs2-Fix-pointer-cast-byte-order-issue.patch diff --git a/0001-libgfs2-Fix-pointer-cast-byte-order-issue.patch b/0001-libgfs2-Fix-pointer-cast-byte-order-issue.patch new file mode 100644 index 0000000..e62ba20 --- /dev/null +++ b/0001-libgfs2-Fix-pointer-cast-byte-order-issue.patch @@ -0,0 +1,52 @@ +From 57553571df2f33ec45a81fa5599873ddfc890c92 Mon Sep 17 00:00:00 2001 +From: Andrew Price +Date: Thu, 6 Sep 2018 14:28:19 +0100 +Subject: [PATCH] libgfs2: Fix pointer cast byte order issue + +lgfs2_field_assign() currently uses pointer casting to achieve generic +integer assignment based on the width of the field, but this is broken +as a uin32_t field can be assigned the value from the high bytes of the +uint64_t value, for instance. To fix this, store the value into a +uint64_t before casting to the narrower types. + +Signed-off-by: Andrew Price +--- + gfs2/libgfs2/meta.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/gfs2/libgfs2/meta.c b/gfs2/libgfs2/meta.c +index a8289466..e0ea4912 100644 +--- a/gfs2/libgfs2/meta.c ++++ b/gfs2/libgfs2/meta.c +@@ -940,6 +940,7 @@ int lgfs2_field_str(char *str, const size_t size, const char *blk, const struct + int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const void *val) + { + char *fieldp = blk + field->offset; ++ uint64_t num = *(uint64_t *)val; + + if (field->flags & LGFS2_MFF_UUID) { + memcpy(fieldp, val, 16); +@@ -959,16 +960,16 @@ int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const voi + + switch(field->length) { + case sizeof(uint8_t): +- *fieldp = *(uint8_t *)val; ++ *fieldp = (uint8_t)num; + return 0; + case sizeof(uint16_t): +- *(uint16_t *)fieldp = cpu_to_be16(*(uint16_t *)val); ++ *(uint16_t *)fieldp = cpu_to_be16((uint16_t)num); + return 0; + case sizeof(uint32_t): +- *(uint32_t *)fieldp = cpu_to_be32(*(uint32_t *)val); ++ *(uint32_t *)fieldp = cpu_to_be32((uint32_t)num); + return 0; + case sizeof(uint64_t): +- *(uint64_t *)fieldp = cpu_to_be64(*(uint64_t *)val); ++ *(uint64_t *)fieldp = cpu_to_be64((uint64_t)num); + return 0; + default: + /* Will never happen */ +-- +2.33.0 + diff --git a/gfs2-utils.spec b/gfs2-utils.spec index 892d5d2..8cc5856 100644 --- a/gfs2-utils.spec +++ b/gfs2-utils.spec @@ -1,12 +1,14 @@ Name: gfs2-utils Version: 3.2.0 -Release: 5 +Release: 6 Summary: Global Filesystem Utilities License: GPLv2+ and LGPLv2+ URL: https://pagure.io/gfs2-utils Source0: https://releases.pagure.org/gfs2-utils/gfs2-utils-%{version}.tar.gz +Patch0001: 0001-libgfs2-Fix-pointer-cast-byte-order-issue.patch + BuildRequires: ncurses-devel kernel-headers automake libtool zlib-devel gettext-devel BuildRequires: bison flex libblkid-devel libuuid-devel check-devel @@ -51,6 +53,9 @@ make -C gfs2 install DESTDIR=%{buildroot} %exclude %{_mandir}/man8/gfs2_lockcapture.8.gz %changelog +* Thu Oct 19 2023 liyuanyuan - 3.2.0-6 +- libgfs2: Fix pointer cast byte order issue + * Tue Jan 21 2020 daiqianwen - 3.2.0-5 - Type:bugfix - ID:NA -- Gitee