diff --git a/NEWS.md b/NEWS.md index a82f977..e8c02b1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ### 2.15 (unreleased) - fixed Cygwin compilation by not passing ELF-specific linker flags +- fixed undefined behavior in little-endian field parsing - fixed MSI MsiDigitalSignatureEx digest ordering during signing and verification - fixed verification to report failure when timestamp verification fails - fixed replacing a script signature block that starts the file or follows a diff --git a/appx.c b/appx.c index 18eb79c..0476c20 100644 --- a/appx.c +++ b/appx.c @@ -2841,7 +2841,8 @@ static uint32_t fileGetU32(FILE *file) if (size != 4) { return 0; /* FAILED */ } - return (uint32_t)(b[3] << 24 | b[2] << 16 | b[1] << 8 | b[0]); + return ((uint32_t)b[3] << 24) | ((uint32_t)b[2] << 16) | + ((uint32_t)b[1] << 8) | (uint32_t)b[0]; } /* coverity[ -tainted_data_return ] */ @@ -2852,7 +2853,7 @@ static uint16_t fileGetU16(FILE *file) if (size != 2) { return 0; /* FAILED */ } - return (uint16_t)(b[1] << 8 | b[0]); + return (uint16_t)((uint32_t)b[1] << 8 | b[0]); } static uint64_t bufferGetU64(uint8_t *buffer, uint64_t *pos) @@ -2864,17 +2865,17 @@ static uint64_t bufferGetU64(uint8_t *buffer, uint64_t *pos) static uint32_t bufferGetU32(uint8_t *buffer, uint64_t *pos) { - uint32_t ret = (uint32_t)(buffer[*pos + 3] << 24 | \ - buffer[*pos + 2] << 16 | \ - buffer[*pos + 1] << 8 | \ - buffer[*pos]); + uint32_t ret = ((uint32_t)buffer[*pos + 3] << 24) | \ + ((uint32_t)buffer[*pos + 2] << 16) | \ + ((uint32_t)buffer[*pos + 1] << 8) | \ + (uint32_t)buffer[*pos]; *pos += 4; return ret; } static uint16_t bufferGetU16(uint8_t *buffer, uint64_t *pos) { - uint16_t ret = (uint16_t)(buffer[*pos + 1] << 8 | buffer[*pos]); + uint16_t ret = (uint16_t)((uint32_t)buffer[*pos + 1] << 8 | buffer[*pos]); *pos += 2; return ret; } diff --git a/osslsigncode.h b/osslsigncode.h index 92819eb..2c47ad6 100644 --- a/osslsigncode.h +++ b/osslsigncode.h @@ -104,13 +104,13 @@ #define GET_UINT8_LE(p) ((const u_char *)(p))[0] -#define GET_UINT16_LE(p) (uint16_t)(((const u_char *)(p))[0] | \ - (((const u_char *)(p))[1] << 8)) +#define GET_UINT16_LE(p) (uint16_t)((uint32_t)((const u_char *)(p))[0] | \ + ((uint32_t)((const u_char *)(p))[1] << 8)) -#define GET_UINT32_LE(p) (uint32_t)(((const u_char *)(p))[0] | \ - (((const u_char *)(p))[1] << 8) | \ - (((const u_char *)(p))[2] << 16) | \ - (((const u_char *)(p))[3] << 24)) +#define GET_UINT32_LE(p) (uint32_t)((uint32_t)((const u_char *)(p))[0] | \ + ((uint32_t)((const u_char *)(p))[1] << 8) | \ + ((uint32_t)((const u_char *)(p))[2] << 16) | \ + ((uint32_t)((const u_char *)(p))[3] << 24)) #define PUT_UINT8_LE(i, p) ((u_char *)(p))[0] = (u_char)((i) & 0xff);