asn1/a_int.c: clean up asn1_get_int64.
authorAndy Polyakov <appro@openssl.org>
Sat, 15 Apr 2017 13:53:50 +0000 (15:53 +0200)
committerAndy Polyakov <appro@openssl.org>
Tue, 25 Apr 2017 21:54:38 +0000 (23:54 +0200)
commit6fc37bee4a5f81d8f00e6ad45865b6b697163f06
tree1b2fba57d8ddb9e82212ec9cf8975dfefe028416
parenta84627454ba887bee7b6563a5101c2ce065ae386
asn1/a_int.c: clean up asn1_get_int64.

Trouble was that integer negation wasn't producing *formally* correct
result in platform-neutral sense. Formally correct thing to do is
-(int64_t)u, but this triggers undefined behaviour for one value that
would still be representable in ASN.1. The trigger was masked with
(int64_t)(0-u), but this is formally inappropriate for values other
than the problematic one. [Also reorder branches to favour most-likely
paths and harmonize asn1_string_set_int64 with asn1_get_int64].]

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3231)

(cherry picked from commit 786b6a45fbecc068d0fb8b05252a9228e0661c63)
crypto/asn1/a_int.c