From: Kurt Roeckx Date: Sun, 17 Jul 2016 13:28:09 +0000 (+0200) Subject: Cast to an unsigned type before negating X-Git-Tag: OpenSSL_1_0_2l~41 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e5afec1831248c767be7c5844a88535dabecc01a;p=oweals%2Fopenssl.git Cast to an unsigned type before negating llvm's ubsan reported: runtime error: negation of -9223372036854775808 cannot be represented in type 'long'; cast to an unsigned type to negate this value to itself Found using afl Reviewed-by: Rich Salz GH: #1325 (cherry picked from commit 1618679ac478c8f41fc5f320fb4d8a33883b3868) --- diff --git a/crypto/asn1/x_long.c b/crypto/asn1/x_long.c index 98562a18ba..efdf574e24 100644 --- a/crypto/asn1/x_long.c +++ b/crypto/asn1/x_long.c @@ -126,7 +126,7 @@ static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, * set. */ if (ltmp < 0) - utmp = -ltmp - 1; + utmp = -(unsigned long)ltmp - 1; else utmp = ltmp; clen = BN_num_bits_word(utmp); diff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c index 987fe068c6..eb3ab75934 100644 --- a/crypto/bio/b_print.c +++ b/crypto/bio/b_print.c @@ -502,7 +502,7 @@ fmtint(char **sbuffer, if (!(flags & DP_F_UNSIGNED)) { if (value < 0) { signvalue = '-'; - uvalue = -value; + uvalue = -(unsigned LLONG)value; } else if (flags & DP_F_PLUS) signvalue = '+'; else if (flags & DP_F_SPACE)