summaryrefslogtreecommitdiffstats
path: root/lib/libcrypto/asn1/a_bitstr.c
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2018-05-12 17:44:31 +0000
committerjsing <jsing@openbsd.org>2018-05-12 17:44:31 +0000
commit764fbd16b5dc47982af6769ad9ba148ef2fc072b (patch)
tree3413e1802ff227c97a4ac39ad3c734f67277af2e /lib/libcrypto/asn1/a_bitstr.c
parentAdd a missing bounds check in c2i_ASN1_BIT_STRING(). (diff)
downloadwireguard-openbsd-764fbd16b5dc47982af6769ad9ba148ef2fc072b.tar.xz
wireguard-openbsd-764fbd16b5dc47982af6769ad9ba148ef2fc072b.zip
Cleanup c2i_ASN1_BIT_STRING() code.
Avoid overloading a variable to store both a value and an error code - we can simply inline the error calls (as done everywhere else). Remove a bunch of unnecessary parentheses and tidy a few other things. With input from tb@. ok inoguchi@ tb@
Diffstat (limited to 'lib/libcrypto/asn1/a_bitstr.c')
-rw-r--r--lib/libcrypto/asn1/a_bitstr.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/lib/libcrypto/asn1/a_bitstr.c b/lib/libcrypto/asn1/a_bitstr.c
index 3800c218a18..7fa5af9bbba 100644
--- a/lib/libcrypto/asn1/a_bitstr.c
+++ b/lib/libcrypto/asn1/a_bitstr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: a_bitstr.c,v 1.26 2018/05/12 17:39:05 jsing Exp $ */
+/* $OpenBSD: a_bitstr.c,v 1.27 2018/05/12 17:44:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -135,15 +135,15 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
int i;
if (len < 1) {
- i = ASN1_R_STRING_TOO_SHORT;
+ ASN1error(ASN1_R_STRING_TOO_SHORT);
goto err;
}
- if ((a == NULL) || ((*a) == NULL)) {
+ if (a == NULL || *a == NULL) {
if ((ret = ASN1_BIT_STRING_new()) == NULL)
return (NULL);
} else
- ret = (*a);
+ ret = *a;
p = *pp;
i = *(p++);
@@ -152,17 +152,17 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
goto err;
}
- /* We do this to preserve the settings. If we modify
- * the settings, via the _set_bit function, we will recalculate
- * on output */
- ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
- ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
-
- if (len-- > 1) /* using one because of the bits left byte */
- {
- s = malloc(len);
- if (s == NULL) {
- i = ERR_R_MALLOC_FAILURE;
+ /*
+ * We do this to preserve the settings. If we modify the settings,
+ * via the _set_bit function, we will recalculate on output.
+ */
+ ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */
+ ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */
+
+ /* using one because of the bits left byte */
+ if (len-- > 1) {
+ if ((s = malloc(len)) == NULL) {
+ ASN1error(ERR_R_MALLOC_FAILURE);
goto err;
}
memcpy(s, p, len);
@@ -171,19 +171,22 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
} else
s = NULL;
- ret->length = (int)len;
free(ret->data);
ret->data = s;
+ ret->length = (int)len;
ret->type = V_ASN1_BIT_STRING;
+
if (a != NULL)
- (*a) = ret;
+ *a = ret;
+
*pp = p;
+
return (ret);
-err:
- ASN1error(i);
- if ((ret != NULL) && ((a == NULL) || (*a != ret)))
+ err:
+ if (a == NULL || *a != ret)
ASN1_BIT_STRING_free(ret);
+
return (NULL);
}