fix default dictionary should be generated for target endianness
v2 cover fix default dictionary should be generated for target endianness
Change from V1: Fix type error, /IheaderHostToLillteEndian/IheaderHostToBigEndian/
The following changes since commit addcfcda84ed6b43b00f569a6060e3b78196ef52:
glib-2.0: disable tests for native builds, and respect ptest for LSB (2013-04-23 13:00:43 +0100)
are available in the git repository at:
git://git.pokylinux.org/poky-contrib hongxu/fix-cracklib
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=hongxu/fix-cracklib
Hongxu Jia (2):
cracklib : fix default dictionary should be generated for target
endianness
craklib:fix testnum and teststr failed
...c-support-dictionary-byte-order-dependent.patch | 322 ++++++++++++++++++++ ...02-craklib-fix-testnum-and-teststr-failed.patch | 53 ++++ meta/recipes-extended/cracklib/cracklib_2.8.22.bb | 4 +- 3 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch create mode 100644 meta/recipes-extended/cracklib/cracklib/0002-craklib-fix-testnum-and-teststr-failed.patch
Signature · 1 line
1.7.10.4
PATCH v2 1/2 cracklib: fix default dictionary should be generated for target endianness
The previous dict files are NOT byte-order independent, in fact they are probably ARCHITECTURE SPECIFIC.
Create the dict files in big endian, and convert to host endian while load them. This could fix the endian issue on multiple platform.
[Bug #4419]
--- ...c-support-dictionary-byte-order-dependent.patch | 322 ++++++++++++++++++++ meta/recipes-extended/cracklib/cracklib_2.8.22.bb | 3 +- 2 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch
meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch new file +322 -0
@@ -0,0 +1,322 @@ +From dae29a98c066bc67bb5ba12219d5fd68a8675514 Mon Sep 17 00:00:00 2001 +From: Hongxu Jia <[email protected]> +Date: Fri, 26 Apr 2013 20:44:10 +0800 +Subject: [PATCH] packlib.c: support dictionary byte-order dependent + +The previous dict files are NOT byte-order independent, in fact they are +probably ARCHITECTURE SPECIFIC. +Create the dict files in big endian, and convert to host endian while +load them. This could fix the endian issue on multiple platform. + +Signed-off-by: Hongxu Jia <[email protected]> +Upstream-Status: Pending +--- + lib/packlib.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 204 insertions(+), 4 deletions(-) + +diff --git a/lib/packlib.c b/lib/packlib.c +index 8f32d14..323ee83 100644 +--- a/lib/packlib.c ++++ b/lib/packlib.c +@@ -16,6 +16,9 @@ + #ifdef HAVE_STDINT_H + #include <stdint.h> + #endif ++ ++#define _BSD_SOURCE /* See feature_test_macros(7) */ ++#include <endian.h> + #include "packer.h" + + static const char vers_id[] = "packlib.c : v2.3p2 Alec Muffett 18 May 1993"; +@@ -45,6 +48,182 @@ typedef struct + char data_get[NUMWORDS][MAXWORDLEN]; + } PWDICT64; + ++enum{ ++ en_is32, ++ en_is64 ++}; ++ ++static int ++IheaderHostToBigEndian(char *pHeader, int nBitType) ++{ ++ if (nBitType == en_is64) ++ { ++ struct pi_header64 *pHeader64 = (struct pi_header64*)pHeader; ++ ++ pHeader64->pih_magic = htobe64(pHeader64->pih_magic); ++ pHeader64->pih_numwords = htobe64(pHeader64->pih_numwords); ++ pHeader64->pih_blocklen = htobe16(pHeader64->pih_blocklen); ++ pHeader64->pih_pad = htobe16(pHeader64->pih_pad); ++ ++#if DEBUG ++ printf("Header64: magic %x, numwords %x, blocklen %x, pad %x\n", ++ pHeader64->pih_magic, pHeader64->pih_numwords, ++ pHeader64->pih_blocklen, pHeader64->pih_pad); ++#endif ++ } ++ else if (nBitType == en_is32) ++ { ++ struct pi_header *pHeader32 = (struct pi_header*)pHeader; ++ ++ pHeader32->pih_magic = htobe32(pHeader32->pih_magic); ++ pHeader32->pih_numwords = htobe32(pHeader32->pih_numwords); ++ pHeader32->pih_blocklen = htobe16(pHeader32->pih_blocklen); ++ pHeader32->pih_pad = htobe16(pHeader32->pih_pad); ++ ++#if DEBUG ++ printf("Header32: magic %x, numwords %x, blocklen %x, pad %x\n", ++ pHeader32->pih_magic, pHeader32->pih_numwords, ++ pHeader32->pih_blocklen, pHeader32->pih_pad); ++#endif ++ } ++ else ++ { ++ fprintf(stderr, "Neither 32 or 64: %d\n", nBitType); ++ return (-1); ++ } ++ ++ return 0; ++} ++ ++static int ++IheaderBigEndianToHost(char *pHeader, int nBitType) ++{ ++ if (nBitType == en_is64) ++ { ++ struct pi_header64 *pHeader64 = (struct pi_header64*)pHeader; ++ ++ pHeader64->pih_magic = be64toh(pHeader64->pih_magic); ++ pHeader64->pih_numwords = be64toh(pHeader64->pih_numwords); ++ pHeader64->pih_blocklen = be16toh(pHeader64->pih_blocklen); ++ pHeader64->pih_pad = be16toh(pHeader64->pih_pad); ++ ++#if DEBUG ++ printf("Header64: magic %x, numwords %x, blocklen %x, pad %x\n", ++ pHeader64->pih_magic, pHeader64->pih_numwords, ++ pHeader64->pih_blocklen, pHeader64->pih_pad); ++#endif ++ } ++ else if (nBitType == en_is32) ++ { ++ struct pi_header *pHeader32 = (struct pi_header*)pHeader; ++ ++ pHeader32->pih_magic = be32toh(pHeader32->pih_magic); ++ pHeader32->pih_numwords = be32toh(pHeader32->pih_numwords); ++ pHeader32->pih_blocklen = be16toh(pHeader32->pih_blocklen); ++ pHeader32->pih_pad = be16toh(pHeader32->pih_pad); ++ ++#if DEBUG ++ printf("Header32: magic %x, numwords %x, blocklen %x, pad %x\n", ++ pHeader32->pih_magic, pHeader32->pih_numwords, ++ pHeader32->pih_blocklen, pHeader32->pih_pad); ++#endif ++ } ++ else ++ { ++ fprintf(stderr, "Neither 32 or 64: %d\n", nBitType); ++ return (-1); ++ } ++ ++ return 0; ++} ++ ++static int ++HwmsHostToBigEndian(char *pHwms, int nLen,int nBitType) ++{ ++ int i = 0; ++ ++ if (nBitType == en_is64) ++ { ++ uint64_t *pHwms64 = (uint64_t*)pHwms; ++ ++ for (i = 0; i < nLen / sizeof(uint64_t); i++) ++ { ++ *pHwms64++ = htobe64(*pHwms64); ++ } ++ ++ } ++ else if (nBitType == en_is32) ++ { ++ uint32_t *pHwms32 = (uint32_t*)pHwms; ++ ++ for (i = 0; i < nLen / sizeof(uint32_t); i++) ++ { ++ *pHwms32++ = htobe32(*pHwms32); ++ } ++ ++ } ++ else ++ { ++ fprintf(stderr, "Neither 32 or 64: %d\n", nBitType); ++ return (-1); ++ } ++ ++#if DEBUG ++ for (i = 0; i < nLen; i+=8) ++ { ++ printf("hwms%s: %02X %02X %02X %02X %02X %02X %02X %02X\n", ++ nBitType==en_is64?"64":"32", pHwms[i+0]&0xFF, pHwms[i+1]&0xFF, ++ pHwms[i+2]&0xFF, pHwms[i+3]&0xFF, pHwms[i+4]&0xFF, ++ pHwms[i+5]&0xFF, pHwms[i+6]&0xFF, pHwms[i+7]&0xFF); ++ } ++#endif ++ ++ return 0; ++} ++ ++static int ++HwmsBigEndianToHost(char *pHwms, int nLen, int nBitType) ++{ ++ int i = 0; ++ ++ if (nBitType == en_is64) ++ { ++ uint64_t *pHwms64 = (uint64_t*)pHwms; ++ ++ for (i = 0; i < nLen / sizeof(uint64_t); i++) ++ { ++ *pHwms64++ = be64toh(*pHwms64); ++ } ++ ++ } ++ else if (nBitType == en_is32) ++ { ++ uint32_t *pHwms32 = (uint32_t*)pHwms; ++ ++ for (i = 0; i < nLen / sizeof(uint32_t); i++) ++ { ++ *pHwms32++ = be32toh(*pHwms32); ++ } ++ ++ } ++ else ++ { ++ fprintf(stderr, "Neither 32 or 64: %d\n", nBitType); ++ return (-1); ++ } ++ ++#if DEBUG ++ for (i = 0; i < nLen; i+=8) ++ { ++ printf("hwms%s: %02X %02X %02X %02X %02X %02X %02X %02X\n", ++ nBitType==en_is64?"64":"32", pHwms[i+0]&0xFF, pHwms[i+1]&0xFF, ++ pHwms[i+2]&0xFF, pHwms[i+3]&0xFF, pHwms[i+4]&0xFF, ++ pHwms[i+5]&0xFF, pHwms[i+6]&0xFF, pHwms[i+7]&0xFF); ++ } ++#endif ++ ++ return 0; ++} + + static int + _PWIsBroken64(FILE *ifp) +@@ -57,6 +236,7 @@ _PWIsBroken64(FILE *ifp) + return 0; + } + ++ IheaderBigEndianToHost((char *) &pdesc64.header, en_is64); + return (pdesc64.header.pih_magic == PIH_MAGIC); + } + +@@ -149,7 +329,11 @@ PWOpen(prefix, mode) + pdesc.header.pih_blocklen = NUMWORDS; + pdesc.header.pih_numwords = 0; + +- fwrite((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp); ++ struct pi_header tmpheader32; ++ ++ memcpy(&tmpheader32, &pdesc.header, sizeof(pdesc.header)); ++ IheaderHostToBigEndian((char *) &tmpheader32, en_is32); ++ fwrite((char *) &tmpheader32, sizeof(tmpheader32), 1, ifp); + } else + { + pdesc.flags &= ~PFOR_WRITE; +@@ -173,6 +357,7 @@ PWOpen(prefix, mode) + return ((PWDICT *) 0); + } + ++ IheaderBigEndianToHost((char *) &pdesc.header, en_is32); + if ((pdesc.header.pih_magic == 0) || (pdesc.header.pih_numwords == 0)) + { + /* uh-oh. either a broken "64-bit" file or a garbage file. */ +@@ -195,6 +380,7 @@ PWOpen(prefix, mode) + } + return ((PWDICT *) 0); + } ++ IheaderBigEndianToHost((char *) &pdesc64.header, en_is64); + if (pdesc64.header.pih_magic != PIH_MAGIC) + { + /* nope, not "64-bit" after all */ +@@ -290,6 +476,7 @@ PWOpen(prefix, mode) + { + pdesc.flags &= ~PFOR_USEHWMS; + } ++ HwmsBigEndianToHost((char*)pdesc64.hwms, sizeof(pdesc64.hwms), en_is64); + for (i = 0; i < sizeof(pdesc.hwms) / sizeof(pdesc.hwms[0]); i++) + { + pdesc.hwms[i] = pdesc64.hwms[i]; +@@ -299,6 +486,7 @@ PWOpen(prefix, mode) + { + pdesc.flags &= ~PFOR_USEHWMS; + } ++ HwmsBigEndianToHost((char*)pdesc.hwms, sizeof(pdesc.hwms), en_is32); + #if DEBUG + for (i=1; i<=0xff; i++) + { +@@ -332,7 +520,11 @@ PWClose(pwp) + return (-1); + } + +- if (!fwrite((char *) &pwp->header, sizeof(pwp->header), 1, pwp->ifp)) ++ struct pi_header tmpheader32; ++ ++ memcpy(&tmpheader32, &pwp->header, sizeof(pwp->header)); ++ IheaderHostToBigEndian((char *) &tmpheader32, en_is32); ++ if (!fwrite((char *) &tmpheader32, sizeof(tmpheader32), 1, pwp->ifp)) + { + fprintf(stderr, "index magic fwrite failed\n"); + return (-1); +@@ -351,7 +543,12 @@ PWClose(pwp) + printf("hwm[%02x] = %d\n", i, pwp->hwms[i]); + #endif + } +- fwrite(pwp->hwms, 1, sizeof(pwp->hwms), pwp->wfp); ++ ++ PWDICT tmp_pwp; ++ ++ memcpy(&tmp_pwp, pwp, sizeof(PWDICT)); ++ HwmsHostToBigEndian(tmp_pwp.hwms, sizeof(tmp_pwp.hwms), en_is32); ++ fwrite(tmp_pwp.hwms, 1, sizeof(tmp_pwp.hwms), pwp->wfp); + } + } + +@@ -405,7 +602,8 @@ PutPW(pwp, string) + + datum = (uint32_t) ftell(pwp->dfp); + +- fwrite((char *) &datum, sizeof(datum), 1, pwp->ifp); ++ uint32_t tmpdatum = htobe32(datum); ++ fwrite((char *) &tmpdatum, sizeof(tmpdatum), 1, pwp->ifp); + + fputs(pwp->data_put[0], pwp->dfp); + putc(0, pwp->dfp); +@@ -473,6 +671,7 @@ GetPW(pwp, number) + perror("(index fread failed)"); + return ((char *) 0); + } ++ datum64 = be64toh(datum64); + datum = datum64; + } else { + if (fseek(pwp->ifp, sizeof(struct pi_header) + (thisblock * sizeof(uint32_t)), 0)) +@@ -486,6 +685,7 @@ GetPW(pwp, number) + perror("(index fread failed)"); + return ((char *) 0); + } ++ datum = be32toh(datum); + } + + int r = 1; +-- +1.7.10.4 +
meta/recipes-extended/cracklib/cracklib_2.8.22.bb +2 -1
@@ -10,7 +10,8 @@ PR ="r0" EXTRA_OECONF = "--without-python" -SRC_URI = "${SOURCEFORGE_MIRROR}/cracklib/cracklib-${PV}.tar.gz" +SRC_URI = "${SOURCEFORGE_MIRROR}/cracklib/cracklib-${PV}.tar.gz \ + file://0001-packlib.c-support-dictionary-byte-order-dependent.patch" SRC_URI[md5sum] = "463177b5c29c7a598c991e12a4898e06" SRC_URI[sha256sum] = "feaff49bfb513ec10b2618c00d2f7f60776ba93fcc5fa22dd3479dd9cad9f770"
Signature · 1 line
1.7.10.4
Re: [PATCH 1/2] cracklib: fix default dictionary should be generated for target endianness
Quoted 5 lines · Hongxu Jia
The previous dict files are NOT byte-order independent, in fact they are probably ARCHITECTURE SPECIFIC.
Create the dict files in big endian, and convert to host endian while load them. This could fix the endian issue on multiple platform.
Problem with this fix is that is writes files out on first time it runs, this means it will not work correctly on Read-Only FS, is there a solution that can be solved on the host build machine.
Sau!
Quoted 352 lines
[Bug #4419]
Signed-off-by Hongxu Jia <[email protected]>--- ...c-support-dictionary-byte-order-dependent.patch | 322 ++++++++++++++++++++ meta/recipes-extended/cracklib/cracklib_2.8.22.bb | 3 +- 2 files changed, 324 insertions(+), 1 deletion(-)create mode 100644
meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patchmeta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch new file +322
-0@@ -0,0 +1,322 @@ +From dae29a98c066bc67bb5ba12219d5fd68a8675514 Mon Sep 17 00:00:00 2001 +From: Hongxu Jia <[email protected]> +Date: Fri, 26 Apr 2013 20:44:10 +0800 +Subject: [PATCH] packlib.c: support dictionary byte-order dependent + +The previous dict files are NOT byte-order independent, in fact they are +probably ARCHITECTURE SPECIFIC. +Create the dict files in big endian, and convert to host endian while +load them. This could fix the endian issue on multiple platform. + +Signed-off-by: Hongxu Jia <[email protected]> +Upstream-Status: Pending +--- + lib/packlib.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 204 insertions(+), 4 deletions(-) + +diff --git a/lib/packlib.c b/lib/packlib.c +index 8f32d14..323ee83 100644 +--- a/lib/packlib.c ++++ b/lib/packlib.c +@@ -16,6 +16,9 @@ + #ifdef HAVE_STDINT_H + #include <stdint.h> + #endif ++ ++#define _BSD_SOURCE /* See feature_test_macros(7) */ ++#include <endian.h> + #include "packer.h" + + static const char vers_id[] = "packlib.c : v2.3p2 Alec Muffett 18 May 1993"; +@@ -45,6 +48,182 @@ typedef struct + char data_get[NUMWORDS][MAXWORDLEN]; + } PWDICT64; + ++enum{ ++ en_is32, ++ en_is64 ++}; ++ ++static int ++IheaderHostToBigEndian(char *pHeader, int nBitType) ++{ ++ if (nBitType == en_is64) ++ { ++ struct pi_header64 *pHeader64 = (struct pi_header64*)pHeader; ++ ++ pHeader64->pih_magic = htobe64(pHeader64->pih_magic); ++ pHeader64->pih_numwords = htobe64(pHeader64->pih_numwords); ++ pHeader64->pih_blocklen = htobe16(pHeader64->pih_blocklen); ++ pHeader64->pih_pad = htobe16(pHeader64->pih_pad); ++ ++#if DEBUG ++ printf("Header64: magic %x, numwords %x, blocklen %x, pad %x\n", ++ pHeader64->pih_magic, pHeader64->pih_numwords, ++ pHeader64->pih_blocklen, pHeader64->pih_pad); ++#endif ++ } ++ else if (nBitType == en_is32) ++ { ++ struct pi_header *pHeader32 = (struct pi_header*)pHeader; ++ ++ pHeader32->pih_magic = htobe32(pHeader32->pih_magic); ++ pHeader32->pih_numwords = htobe32(pHeader32->pih_numwords); ++ pHeader32->pih_blocklen = htobe16(pHeader32->pih_blocklen); ++ pHeader32->pih_pad = htobe16(pHeader32->pih_pad); ++ ++#if DEBUG ++ printf("Header32: magic %x, numwords %x, blocklen %x, pad %x\n", ++ pHeader32->pih_magic, pHeader32->pih_numwords, ++ pHeader32->pih_blocklen, pHeader32->pih_pad); ++#endif ++ } ++ else ++ { ++ fprintf(stderr, "Neither 32 or 64: %d\n", nBitType); ++ return (-1); ++ } ++ ++ return 0; ++} ++ ++static int ++IheaderBigEndianToHost(char *pHeader, int nBitType) ++{ ++ if (nBitType == en_is64) ++ { ++ struct pi_header64 *pHeader64 = (struct pi_header64*)pHeader; ++ ++ pHeader64->pih_magic = be64toh(pHeader64->pih_magic); ++ pHeader64->pih_numwords = be64toh(pHeader64->pih_numwords); ++ pHeader64->pih_blocklen = be16toh(pHeader64->pih_blocklen); ++ pHeader64->pih_pad = be16toh(pHeader64->pih_pad); ++ ++#if DEBUG ++ printf("Header64: magic %x, numwords %x, blocklen %x, pad %x\n", ++ pHeader64->pih_magic, pHeader64->pih_numwords, ++ pHeader64->pih_blocklen, pHeader64->pih_pad); ++#endif ++ } ++ else if (nBitType == en_is32) ++ { ++ struct pi_header *pHeader32 = (struct pi_header*)pHeader; ++ ++ pHeader32->pih_magic = be32toh(pHeader32->pih_magic); ++ pHeader32->pih_numwords = be32toh(pHeader32->pih_numwords); ++ pHeader32->pih_blocklen = be16toh(pHeader32->pih_blocklen); ++ pHeader32->pih_pad = be16toh(pHeader32->pih_pad); ++ ++#if DEBUG ++ printf("Header32: magic %x, numwords %x, blocklen %x, pad %x\n", ++ pHeader32->pih_magic, pHeader32->pih_numwords, ++ pHeader32->pih_blocklen, pHeader32->pih_pad); ++#endif ++ } ++ else ++ { ++ fprintf(stderr, "Neither 32 or 64: %d\n", nBitType); ++ return (-1); ++ } ++ ++ return 0; ++} ++ ++static int ++HwmsHostToBigEndian(char *pHwms, int nLen,int nBitType) ++{ ++ int i = 0; ++ ++ if (nBitType == en_is64) ++ { ++ uint64_t *pHwms64 = (uint64_t*)pHwms; ++ ++ for (i = 0; i < nLen / sizeof(uint64_t); i++) ++ { ++ *pHwms64++ = htobe64(*pHwms64); ++ } ++ ++ } ++ else if (nBitType == en_is32) ++ { ++ uint32_t *pHwms32 = (uint32_t*)pHwms; ++ ++ for (i = 0; i < nLen / sizeof(uint32_t); i++) ++ { ++ *pHwms32++ = htobe32(*pHwms32); ++ } ++ ++ } ++ else ++ { ++ fprintf(stderr, "Neither 32 or 64: %d\n", nBitType); ++ return (-1); ++ } ++ ++#if DEBUG ++ for (i = 0; i < nLen; i+=8) ++ { ++ printf("hwms%s: %02X %02X %02X %02X %02X %02X %02X %02X\n", ++ nBitType==en_is64?"64":"32", pHwms[i+0]&0xFF, pHwms[i+1]&0xFF, ++ pHwms[i+2]&0xFF, pHwms[i+3]&0xFF, pHwms[i+4]&0xFF, ++ pHwms[i+5]&0xFF, pHwms[i+6]&0xFF, pHwms[i+7]&0xFF); ++ } ++#endif ++ ++ return 0; ++} ++ ++static int ++HwmsBigEndianToHost(char *pHwms, int nLen, int nBitType) ++{ ++ int i = 0; ++ ++ if (nBitType == en_is64) ++ { ++ uint64_t *pHwms64 = (uint64_t*)pHwms; ++ ++ for (i = 0; i < nLen / sizeof(uint64_t); i++) ++ { ++ *pHwms64++ = be64toh(*pHwms64); ++ } ++ ++ } ++ else if (nBitType == en_is32) ++ { ++ uint32_t *pHwms32 = (uint32_t*)pHwms; ++ ++ for (i = 0; i < nLen / sizeof(uint32_t); i++) ++ { ++ *pHwms32++ = be32toh(*pHwms32); ++ } ++ ++ } ++ else ++ { ++ fprintf(stderr, "Neither 32 or 64: %d\n", nBitType); ++ return (-1); ++ } ++ ++#if DEBUG ++ for (i = 0; i < nLen; i+=8) ++ { ++ printf("hwms%s: %02X %02X %02X %02X %02X %02X %02X %02X\n", ++ nBitType==en_is64?"64":"32", pHwms[i+0]&0xFF, pHwms[i+1]&0xFF, ++ pHwms[i+2]&0xFF, pHwms[i+3]&0xFF, pHwms[i+4]&0xFF, ++ pHwms[i+5]&0xFF, pHwms[i+6]&0xFF, pHwms[i+7]&0xFF); ++ } ++#endif ++ ++ return 0; ++} + + static int + _PWIsBroken64(FILE *ifp) +@@ -57,6 +236,7 @@ _PWIsBroken64(FILE *ifp) + return 0; + } + ++ IheaderBigEndianToHost((char *) &pdesc64.header, en_is64); + return (pdesc64.header.pih_magic == PIH_MAGIC); + } + +@@ -149,7 +329,11 @@ PWOpen(prefix, mode) + pdesc.header.pih_blocklen = NUMWORDS; + pdesc.header.pih_numwords = 0; + +- fwrite((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp); ++ struct pi_header tmpheader32; ++ ++ memcpy(&tmpheader32, &pdesc.header, sizeof(pdesc.header)); ++ IheaderHostToBigEndian((char *) &tmpheader32, en_is32); ++ fwrite((char *) &tmpheader32, sizeof(tmpheader32), 1, ifp); + } else + { + pdesc.flags &= ~PFOR_WRITE; +@@ -173,6 +357,7 @@ PWOpen(prefix, mode) + return ((PWDICT *) 0); + } + ++ IheaderBigEndianToHost((char *) &pdesc.header, en_is32); + if ((pdesc.header.pih_magic == 0) || (pdesc.header.pih_numwords == 0)) + { + /* uh-oh. either a broken "64-bit" file or a garbage file. */ +@@ -195,6 +380,7 @@ PWOpen(prefix, mode) + } + return ((PWDICT *) 0); + } ++ IheaderBigEndianToHost((char *) &pdesc64.header, en_is64); + if (pdesc64.header.pih_magic != PIH_MAGIC) + { + /* nope, not "64-bit" after all */ +@@ -290,6 +476,7 @@ PWOpen(prefix, mode) + { + pdesc.flags &= ~PFOR_USEHWMS; + } ++ HwmsBigEndianToHost((char*)pdesc64.hwms, sizeof(pdesc64.hwms), en_is64); + for (i = 0; i < sizeof(pdesc.hwms) / sizeof(pdesc.hwms[0]); i++) + { + pdesc.hwms[i] = pdesc64.hwms[i]; +@@ -299,6 +486,7 @@ PWOpen(prefix, mode) + { + pdesc.flags &= ~PFOR_USEHWMS; + } ++ HwmsBigEndianToHost((char*)pdesc.hwms, sizeof(pdesc.hwms), en_is32); + #if DEBUG + for (i=1; i<=0xff; i++) + { +@@ -332,7 +520,11 @@ PWClose(pwp) + return (-1); + } + +- if (!fwrite((char *) &pwp->header, sizeof(pwp->header), 1, pwp->ifp)) ++ struct pi_header tmpheader32; ++ ++ memcpy(&tmpheader32, &pwp->header, sizeof(pwp->header)); ++ IheaderHostToBigEndian((char *) &tmpheader32, en_is32); ++ if (!fwrite((char *) &tmpheader32, sizeof(tmpheader32), 1, pwp->ifp)) + { + fprintf(stderr, "index magic fwrite failed\n"); + return (-1); +@@ -351,7 +543,12 @@ PWClose(pwp) + printf("hwm[%02x] = %d\n", i, pwp->hwms[i]); + #endif + } +- fwrite(pwp->hwms, 1, sizeof(pwp->hwms), pwp->wfp); ++ ++ PWDICT tmp_pwp; ++ ++ memcpy(&tmp_pwp, pwp, sizeof(PWDICT)); ++ HwmsHostToBigEndian(tmp_pwp.hwms, sizeof(tmp_pwp.hwms), en_is32); ++ fwrite(tmp_pwp.hwms, 1, sizeof(tmp_pwp.hwms), pwp->wfp); + } + } + +@@ -405,7 +602,8 @@ PutPW(pwp, string) + + datum = (uint32_t) ftell(pwp->dfp); + +- fwrite((char *) &datum, sizeof(datum), 1, pwp->ifp); ++ uint32_t tmpdatum = htobe32(datum); ++ fwrite((char *) &tmpdatum, sizeof(tmpdatum), 1, pwp->ifp); + + fputs(pwp->data_put[0], pwp->dfp); + putc(0, pwp->dfp); +@@ -473,6 +671,7 @@ GetPW(pwp, number) + perror("(index fread failed)"); + return ((char *) 0); + } ++ datum64 = be64toh(datum64); + datum = datum64; + } else { + if (fseek(pwp->ifp, sizeof(struct pi_header) + (thisblock * sizeof(uint32_t)), 0)) +@@ -486,6 +685,7 @@ GetPW(pwp, number) + perror("(index fread failed)"); + return ((char *) 0); + } ++ datum = be32toh(datum); + } + + int r = 1; +-- +1.7.10.4 +meta/recipes-extended/cracklib/cracklib_2.8.22.bb +2
-1@@ -10,7 +10,8 @@ PR ="r0" EXTRA_OECONF = "--without-python" -SRC_URI = "${SOURCEFORGE_MIRROR}/cracklib/cracklib-${PV}.tar.gz" +SRC_URI = "${SOURCEFORGE_MIRROR}/cracklib/cracklib-${PV}.tar.gz \ + file://0001-packlib.c-support-dictionary-byte-order-dependent.patch" SRC_URI[md5sum] = "463177b5c29c7a598c991e12a4898e06" SRC_URI[sha256sum] = "feaff49bfb513ec10b2618c00d2f7f60776ba93fcc5fa22dd3479dd9cad9f770"
Re: [PATCH 1/2] cracklib: fix default dictionary should be generated for target endianness
Quoted 9 lines · Saul Wold
Quoted 5 lines · Hongxu Jia
The previous dict files are NOT byte-order independent, in fact they are probably ARCHITECTURE SPECIFIC.
Create the dict files in big endian, and convert to host endian while load them. This could fix the endian issue on multiple platform.Problem with this fix is that is writes files out on first time it runs, this means it will not work correctly on Read-Only FS, is there a solution that can be solved on the host build machine.
Sau!
The creation of dict files is still at build time but in big endian rather than host endian, and it could work for Read-Only system.
In meta/recipes-extended/cracklib/cracklib_2.8.22.bb
...
24 do_install_append_class-target() {
25 create-cracklib-dict -o ${D}${datadir}/cracklib/pw_dict
${D}${datadir}/cracklib/cracklib-small
26 }
...
It will invoke the previous function at build time in which create-cracklib-dict is cracklib-native's.
//Hongxu
Quoted 376 lines
Quoted 376 lines
[Bug #4419]
Signed-off-by Hongxu Jia <[email protected]>--- ...c-support-dictionary-byte-order-dependent.patch | 322 ++++++++++++++++++++ meta/recipes-extended/cracklib/cracklib_2.8.22.bb | 3 +- 2 files changed, 324 insertions(+), 1 deletion(-)create mode 100644
meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patchmeta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +0
-0new file mode 100644
index 0000000..fc402ee
---/dev/null
+++b/meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patchmeta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +6
-0@@ -0,0 +1,322 @@ +From dae29a98c066bc67bb5ba12219d5fd68a8675514 Mon Sep 17 00:00:00 2001 +From: Hongxu Jia <[email protected]> +Date: Fri, 26 Apr 2013 20:44:10 +0800 +Subject: [PATCH] packlib.c: support dictionary byte-order dependent + +The previous dict files are NOT byte-order independent, in fact theyare
meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +25
-0+probably ARCHITECTURE SPECIFIC. +Create the dict files in big endian, and convert to host endian while +load them. This could fix the endian issue on multiple platform. + +Signed-off-by: Hongxu Jia <[email protected]> +Upstream-Status: Pending +--- + lib/packlib.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 204 insertions(+), 4 deletions(-) + +diff --git a/lib/packlib.c b/lib/packlib.c +index 8f32d14..323ee83 100644 +--- a/lib/packlib.c ++++ b/lib/packlib.c +@@ -16,6 +16,9 @@ + #ifdef HAVE_STDINT_H + #include <stdint.h> + #endif ++ ++#define _BSD_SOURCE /* See feature_test_macros(7) */ ++#include <endian.h> + #include "packer.h" + + static const char vers_id[] = "packlib.c : v2.3p2 Alec Muffett 18May 1993";
+@@ -45,6 +48,182 @@ typedef structmeta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +22
-0+ char data_get[NUMWORDS][MAXWORDLEN]; + } PWDICT64; + ++enum{ ++ en_is32, ++ en_is64 ++}; ++ ++static int ++IheaderHostToBigEndian(char *pHeader, int nBitType) ++{ ++ if (nBitType == en_is64) ++ { ++ struct pi_header64 *pHeader64 = (struct pi_header64*)pHeader; ++ ++ pHeader64->pih_magic = htobe64(pHeader64->pih_magic); ++ pHeader64->pih_numwords = htobe64(pHeader64->pih_numwords); ++ pHeader64->pih_blocklen = htobe16(pHeader64->pih_blocklen); ++ pHeader64->pih_pad = htobe16(pHeader64->pih_pad); ++ ++#if DEBUG ++ printf("Header64: magic %x, numwords %x, blocklen %x, pad%x\n",
++pHeader64->pih_magic,pHeader64->pih_numwords,
++pHeader64->pih_blocklen,pHeader64->pih_pad);
++#endif++ } ++ else if (nBitType == en_is32) ++ { ++ struct pi_header *pHeader32 = (struct pi_header*)pHeader; ++ ++ pHeader32->pih_magic = htobe32(pHeader32->pih_magic); ++ pHeader32->pih_numwords = htobe32(pHeader32->pih_numwords); ++ pHeader32->pih_blocklen = htobe16(pHeader32->pih_blocklen); ++ pHeader32->pih_pad = htobe16(pHeader32->pih_pad);++
++#if DEBUG
++ printf("Header32: magic %x, numwords %x, blocklen %x, pad
%x\n",
++pHeader32->pih_magic,pHeader32->pih_numwords,
++pHeader32->pih_blocklen,pHeader32->pih_pad);
++#endif++ } ++ else ++ {++
fprintf(stderr, "Neither 32 or 64: %d\n", nBitType);
++ return (-1);
++ }
++
++ return 0;
++}
++
++static int
++IheaderBigEndianToHost(char *pHeader, int nBitType) ++{
++ if (nBitType ==en_is64)
++ {
++ structpi_header64*pHeader64 = (struct pi_header64*)pHeader;
++++ pHeader64->pih_magic = be64toh(pHeader64->pih_magic); ++ pHeader64->pih_numwords = be64toh(pHeader64->pih_numwords); ++ pHeader64->pih_blocklen = be16toh(pHeader64->pih_blocklen); ++ pHeader64->pih_pad = be16toh(pHeader64->pih_pad);++
++#if DEBUG
++ printf("Header64: magic %x, numwords %x, blocklen %x, pad
%x\n",
++pHeader64->pih_magic,pHeader64->pih_numwords,
++pHeader64->pih_blocklen,pHeader64->pih_pad);
++#endif++ } ++ else if (nBitType == en_is32) ++ { ++ struct pi_header *pHeader32 = (struct pi_header*)pHeader; ++ ++ pHeader32->pih_magic = be32toh(pHeader32->pih_magic); ++ pHeader32->pih_numwords = be32toh(pHeader32->pih_numwords); ++ pHeader32->pih_blocklen = be16toh(pHeader32->pih_blocklen); ++ pHeader32->pih_pad = be16toh(pHeader32->pih_pad);++
++#if DEBUG
++ printf("Header32: magic %x, numwords %x, blocklen %x, pad
%x\n",
++pHeader32->pih_magic,pHeader32->pih_numwords,
++pHeader32->pih_blocklen,pHeader32->pih_pad);
++#endif++ } ++ else ++ {++
fprintf(stderr, "Neither 32 or 64: %d\n", nBitType);
++ return (-1);
++ }
++
++ return 0;
++}
++
++static int
++HwmsHostToBigEndian(char *pHwms, int nLen,int nBitType) ++{
++ int i = 0;
++
++ if (nBitType ==en_is64)
++ {
++uint64_t*pHwms64 = (uint64_t*)pHwms;
++
++ for (i = 0; i < nLen /sizeof(uint64_t); i++)
++ {
++ *pHwms64++ =htobe64(*pHwms64);
++ }
++++ } ++ else if (nBitType == en_is32) ++ {++
uint32_t*pHwms32 = (uint32_t*)pHwms;
++
++ for (i = 0; i < nLen /sizeof(uint32_t); i++)
++ {
++ *pHwms32++ =htobe32(*pHwms32);
++ }
++++ } ++ else ++ {++
fprintf(stderr, "Neither 32 or 64: %d\n", nBitType);
++ return (-1);
++ }
++
++#if DEBUG
++ for (i = 0; i < nLen; i+=8)
++ {
++ printf("hwms%s: %02X %02X %02X %02X %02X %02X %02X %02X\n",
++ nBitType==en_is64?"64":"32", pHwms[i+0]&0xFF,
pHwms[i+1]&0xFF,
++ pHwms[i+2]&0xFF, pHwms[i+3]&0xFF, pHwms[i+4]&0xFF,
++ pHwms[i+5]&0xFF, pHwms[i+6]&0xFF, pHwms[i+7]&0xFF);
++ }
++#endif
++
++ return 0;
++}
++
++static int
++HwmsBigEndianToHost(char *pHwms, int nLen, int nBitType) ++{
++ int i = 0;
++
++ if (nBitType ==en_is64)
++ {
++uint64_t*pHwms64 = (uint64_t*)pHwms;
++
++ for (i = 0; i < nLen /sizeof(uint64_t); i++)
++ {
++ *pHwms64++ =be64toh(*pHwms64);
++ }
++++ } ++ else if (nBitType == en_is32) ++ {++
uint32_t*pHwms32 = (uint32_t*)pHwms;
++
++ for (i = 0; i < nLen /sizeof(uint32_t); i++)
++ {
++ *pHwms32++ =be32toh(*pHwms32);
++ }
++++ } ++ else ++ {++
fprintf(stderr, "Neither 32 or 64: %d\n", nBitType);
++ return (-1);
++ }
++
++#if DEBUG
++ for (i = 0; i < nLen; i+=8)
++ {
++ printf("hwms%s: %02X %02X %02X %02X %02X %02X %02X %02X\n",
++ nBitType==en_is64?"64":"32", pHwms[i+0]&0xFF,
pHwms[i+1]&0xFF,
++ pHwms[i+2]&0xFF, pHwms[i+3]&0xFF, pHwms[i+4]&0xFF,
++ pHwms[i+5]&0xFF, pHwms[i+6]&0xFF, pHwms[i+7]&0xFF);
++ }
++#endif
++
++ return 0;
++}meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +30
-0+ + static int + _PWIsBroken64(FILE *ifp) +@@ -57,6 +236,7 @@ _PWIsBroken64(FILE *ifp) + return 0; + } + ++ IheaderBigEndianToHost((char *) &pdesc64.header, en_is64); + return (pdesc64.header.pih_magic == PIH_MAGIC); + } + +@@ -149,7 +329,11 @@ PWOpen(prefix, mode) + pdesc.header.pih_blocklen = NUMWORDS; + pdesc.header.pih_numwords = 0; + +- fwrite((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp); ++ struct pi_header tmpheader32; ++ ++ memcpy(&tmpheader32, &pdesc.header, sizeof(pdesc.header)); ++ IheaderHostToBigEndian((char *) &tmpheader32, en_is32); ++ fwrite((char *) &tmpheader32, sizeof(tmpheader32), 1, ifp); + } else + { + pdesc.flags &= ~PFOR_WRITE; +@@ -173,6 +357,7 @@ PWOpen(prefix, mode) + return ((PWDICT *) 0); + } + ++ IheaderBigEndianToHost((char *) &pdesc.header, en_is32); + if ((pdesc.header.pih_magic == 0) ||(pdesc.header.pih_numwords == 0))
meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +2
-0+ { + /* uh-oh. either a broken "64-bit" file or a garbagefile. */
+@@ -195,6 +380,7 @@PWOpen(prefix, mode)meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +12
-0+ } + return ((PWDICT *) 0); + } ++ IheaderBigEndianToHost((char *) &pdesc64.header, en_is64); + if (pdesc64.header.pih_magic != PIH_MAGIC) + { + /* nope, not "64-bit" after all */ +@@ -290,6 +476,7 @@ PWOpen(prefix, mode) + { + pdesc.flags &= ~PFOR_USEHWMS; + } ++ HwmsBigEndianToHost((char*)pdesc64.hwms,sizeof(pdesc64.hwms),
en_is64);
+ for (i = 0; i < sizeof(pdesc.hwms) /sizeof(pdesc.hwms[0]); i++)meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +7
-0+ { + pdesc.hwms[i] = pdesc64.hwms[i]; +@@ -299,6 +486,7 @@ PWOpen(prefix, mode) + { + pdesc.flags &= ~PFOR_USEHWMS; + } ++ HwmsBigEndianToHost((char*)pdesc.hwms, sizeof(pdesc.hwms),
en_is32);
+ #if DEBUGmeta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +7
-0+ for (i=1; i<=0xff; i++) + { +@@ -332,7 +520,11 @@ PWClose(pwp) + return (-1); + } + +- if (!fwrite((char *) &pwp->header, sizeof(pwp->header), 1,
pwp->ifp))
++ structpi_headertmpheader32;
++++ memcpy(&tmpheader32, &pwp->header, sizeof(pwp->header)); ++ IheaderHostToBigEndian((char *) &tmpheader32, en_is32); ++ if (!fwrite((char *) &tmpheader32, sizeof(tmpheader32), 1,
pwp->ifp))meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +13
-0+ { + fprintf(stderr, "index magic fwrite failed\n"); + return (-1); +@@ -351,7 +543,12 @@ PWClose(pwp) + printf("hwm[%02x] = %d\n", i, pwp->hwms[i]); + #endif + } +- fwrite(pwp->hwms, 1, sizeof(pwp->hwms), pwp->wfp); ++ ++ PWDICT tmp_pwp; ++ ++ memcpy(&tmp_pwp, pwp, sizeof(PWDICT)); ++ HwmsHostToBigEndian(tmp_pwp.hwms, sizeof(tmp_pwp.hwms),
en_is32);
++fwrite(tmp_pwp.hwms, 1, sizeof(tmp_pwp.hwms), pwp->wfp);meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +21
-0+ } + } + +@@ -405,7 +602,8 @@ PutPW(pwp, string) + + datum = (uint32_t) ftell(pwp->dfp); + +- fwrite((char *) &datum, sizeof(datum), 1, pwp->ifp); ++ uint32_t tmpdatum = htobe32(datum); ++ fwrite((char *) &tmpdatum, sizeof(tmpdatum), 1, pwp->ifp); + + fputs(pwp->data_put[0], pwp->dfp); + putc(0, pwp->dfp); +@@ -473,6 +671,7 @@ GetPW(pwp, number) + perror("(index fread failed)"); + return ((char *) 0); + } ++ datum64 = be64toh(datum64); + datum = datum64; + } else { + if (fseek(pwp->ifp, sizeof(struct pi_header) + (thisblock *
sizeof(uint32_t)), 0))
+@@ -486,6 +685,7 @@GetPW(pwp, number)meta/recipes-extended/cracklib/cracklib/0001-packlib.c-support-dictionary-byte-order-dependent.patch +10
-0+ perror("(index fread failed)"); + return ((char *) 0); + } ++ datum = be32toh(datum); + } + + int r = 1; +-- +1.7.10.4 +meta/recipes-extended/cracklib/cracklib_2.8.22.bb +2
-1@@ -10,7 +10,8 @@ PR ="r0" EXTRA_OECONF = "--without-python" -SRC_URI = "${SOURCEFORGE_MIRROR}/cracklib/cracklib-${PV}.tar.gz" +SRC_URI = "${SOURCEFORGE_MIRROR}/cracklib/cracklib-${PV}.tar.gz \ + file://0001-packlib.c-support-dictionary-byte-order-dependent.patch" SRC_URI[md5sum] = "463177b5c29c7a598c991e12a4898e06" SRC_URI[sha256sum] ="
feaff49bfb513ec10b2618c00d2f7f60776ba93fcc5fa22dd3479dd9cad9f770"
PATCH v2 2/2 craklib:fix testnum and teststr failed
In reply to Hongxu JiaError log:
...
$ ./testnum (null).pwd.gz: No such file or directory PWOpen: No such file or directory
$ ./util/teststr (null).pwd.gz: No such file or directory PWOpen: No such file or directory ...
Set DEFAULT_CRACKLIB_DICT as the path of PWOpen
--- ...02-craklib-fix-testnum-and-teststr-failed.patch | 53 ++++++++++++++++++++ meta/recipes-extended/cracklib/cracklib_2.8.22.bb | 3 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 meta/recipes-extended/cracklib/cracklib/0002-craklib-fix-testnum-and-teststr-failed.patch
meta/recipes-extended/cracklib/cracklib/0002-craklib-fix-testnum-and-teststr-failed.patch new file +53 -0
@@ -0,0 +1,53 @@ +From 06f9a88b5dd5597f9198ea0cb34f5e96f180e6e3 Mon Sep 17 00:00:00 2001 +From: Hongxu Jia <[email protected]> +Date: Sat, 27 Apr 2013 16:02:30 +0800 +Subject: [PATCH] craklib:fix testnum and teststr failed + +Error log: +... +$ ./testnum +(null).pwd.gz: No such file or directory +PWOpen: No such file or directory + +$ ./util/teststr +(null).pwd.gz: No such file or directory +PWOpen: No such file or directory +... +Set DEFAULT_CRACKLIB_DICT as the path of PWOpen + +Signed-off-by: Hongxu Jia <[email protected]> +Upstream-Status: Pending +--- + util/testnum.c | 2 +- + util/teststr.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/util/testnum.c b/util/testnum.c +index ae2246d..ca210ff 100644 +--- a/util/testnum.c ++++ b/util/testnum.c +@@ -20,7 +20,7 @@ main () + PWDICT *pwp; + char buffer[STRINGSIZE]; + +- if (!(pwp = PWOpen (NULL, "r"))) ++ if (!(pwp = PWOpen (DEFAULT_CRACKLIB_DICT, "r"))) + { + perror ("PWOpen"); + return (-1); +diff --git a/util/teststr.c b/util/teststr.c +index 2a31fa4..9fb9cda 100644 +--- a/util/teststr.c ++++ b/util/teststr.c +@@ -15,7 +15,7 @@ main () + PWDICT *pwp; + char buffer[STRINGSIZE]; + +- if (!(pwp = PWOpen (NULL, "r"))) ++ if (!(pwp = PWOpen (DEFAULT_CRACKLIB_DICT, "r"))) + { + perror ("PWOpen"); + return (-1); +-- +1.7.10.4 +
meta/recipes-extended/cracklib/cracklib_2.8.22.bb +2 -1
@@ -11,7 +11,8 @@ PR ="r0" EXTRA_OECONF = "--without-python" SRC_URI = "${SOURCEFORGE_MIRROR}/cracklib/cracklib-${PV}.tar.gz \ - file://0001-packlib.c-support-dictionary-byte-order-dependent.patch" + file://0001-packlib.c-support-dictionary-byte-order-dependent.patch \ + file://0002-craklib-fix-testnum-and-teststr-failed.patch" SRC_URI[md5sum] = "463177b5c29c7a598c991e12a4898e06" SRC_URI[sha256sum] = "feaff49bfb513ec10b2618c00d2f7f60776ba93fcc5fa22dd3479dd9cad9f770"
Signature · 1 line
1.7.10.4