Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | fix a endian incompatible error in generating rpm tag |
| 2 | |
| 3 | A flaw was found in the way rpm generating arbitrary tags, which leads to a |
| 4 | incorrect query result, this issue is introduced by a incompatible endianess |
| 5 | when the generating process is executed on different architectures. |
| 6 | |
| 7 | This patch resolves it by taking the byte order that host uses. |
| 8 | |
| 9 | Upstream-Status: Pending |
| 10 | |
| 11 | Signed-off-by: Ming Liu <ming.liu@windriver.com> |
| 12 | --- |
| 13 | tagname.c | 16 ++++++++++++++++ |
| 14 | 1 file changed, 16 insertions(+) |
| 15 | |
| 16 | Index: 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 | } |