blob: 5fb40b6fefe31c1294668bb3c7aed2c234a9080c [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001fix a endian incompatible error in generating rpm tag
2
3A flaw was found in the way rpm generating arbitrary tags, which leads to a
4incorrect query result, this issue is introduced by a incompatible endianess
5when the generating process is executed on different architectures.
6
7This patch resolves it by taking the byte order that host uses.
8
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05009Upstream-Status: Submitted [RPM5 maintainer]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010
11Signed-off-by: Ming Liu <ming.liu@windriver.com>
12---
13 tagname.c | 16 ++++++++++++++++
14 1 file changed, 16 insertions(+)
15
16Index: rpm-5.4.14/rpmdb/tagname.c
17===================================================================
18--- rpm-5.4.14.orig/rpmdb/tagname.c
19+++ rpm-5.4.14/rpmdb/tagname.c
20@@ -3,6 +3,19 @@
21 */
22
23 #include "system.h"
24+#include <endian.h>
25+
26+/* Don't redefine this macro if it already exists */
27+#ifndef le32toh
28+#ifdef __USE_BSD
29+#include <byteswap.h>
30+#if __BYTE_ORDER == __LITTLE_ENDIAN
31+#define le32toh(x) (x)
32+#else
33+#define le32toh(x) __bswap_32(x)
34+#endif
35+#endif /* __USE_BSD */
36+#endif /* le32toh */
37
38 #include <rpmio_internal.h> /* XXX DIGEST_CTX, xtolower, xstrcasecmp */
39 #include <rpmmacro.h>
40@@ -152,7 +165,10 @@ static rpmTag _tagGenerate(const char *s
41 xx = rpmDigestUpdate(ctx, s, nb);
42 xx = rpmDigestFinal(ctx, &digest, &digestlen, 0);
43 if (digest && digestlen > 4) {
44+ /* The tag is stored in a uniform byte order for cross-endian compatibility.
45+ Swap to the host uses. */
46 memcpy(&tag, digest + (digestlen - 4), 4);
47+ tag = le32toh(tag);
48 tag = (rpmTag) (tag & 0x3fffffff);
49 tag = (rpmTag) (tag | 0x40000000);
50 }