summaryrefslogtreecommitdiffstats
path: root/crypto/asn1/a_int.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2020-11-25 13:13:24 +0000
committerMatt Caswell <matt@openssl.org>2020-11-30 10:37:14 +0000
commita07dc8167ba79efe739fef18d7e2ef823bef16c9 (patch)
tree5c25d9ab7f0eff4bf3d7f63e092790095e76eead /crypto/asn1/a_int.c
parent5658470ce7b4fabfd1fa2cdc69bee8d3a5e826f9 (diff)
Fix instances of pointer addition with the NULL pointer
Addition using the NULL pointer (even when adding 0) is undefined behaviour. Recent versions of ubsan are now complaining about this, so we fix various instances. Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/13513)
Diffstat (limited to 'crypto/asn1/a_int.c')
-rw-r--r--crypto/asn1/a_int.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/crypto/asn1/a_int.c b/crypto/asn1/a_int.c
index a90f8c7fb3..98c759cc93 100644
--- a/crypto/asn1/a_int.c
+++ b/crypto/asn1/a_int.c
@@ -79,8 +79,14 @@ static void twos_complement(unsigned char *dst, const unsigned char *src,
unsigned int carry = pad & 1;
/* Begin at the end of the encoding */
- dst += len;
- src += len;
+ if (len != 0) {
+ /*
+ * if len == 0 then src/dst could be NULL, and this would be undefined
+ * behaviour.
+ */
+ dst += len;
+ src += len;
+ }
/* two's complement value: ~value + 1 */
while (len-- != 0) {
*(--dst) = (unsigned char)(carry += *(--src) ^ pad);