summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2018-05-12 17:44:31 +0000
committerjsing <>2018-05-12 17:44:31 +0000
commit4472f3d68a4cfdda378061fd79bb5cfbb348752d (patch)
tree97e30648d91381213f00dfbd41d66a28c60de83a
parent54259dcc7646253fd0374f5fab91657dce17c42e (diff)
downloadopenbsd-4472f3d68a4cfdda378061fd79bb5cfbb348752d.tar.gz
openbsd-4472f3d68a4cfdda378061fd79bb5cfbb348752d.tar.bz2
openbsd-4472f3d68a4cfdda378061fd79bb5cfbb348752d.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@
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index 3800c218a1..7fa5af9bbb 100644
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_bitstr.c,v 1.26 2018/05/12 17:39:05 jsing Exp $ */ 1/* $OpenBSD: a_bitstr.c,v 1.27 2018/05/12 17:44:31 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -135,15 +135,15 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
135 int i; 135 int i;
136 136
137 if (len < 1) { 137 if (len < 1) {
138 i = ASN1_R_STRING_TOO_SHORT; 138 ASN1error(ASN1_R_STRING_TOO_SHORT);
139 goto err; 139 goto err;
140 } 140 }
141 141
142 if ((a == NULL) || ((*a) == NULL)) { 142 if (a == NULL || *a == NULL) {
143 if ((ret = ASN1_BIT_STRING_new()) == NULL) 143 if ((ret = ASN1_BIT_STRING_new()) == NULL)
144 return (NULL); 144 return (NULL);
145 } else 145 } else
146 ret = (*a); 146 ret = *a;
147 147
148 p = *pp; 148 p = *pp;
149 i = *(p++); 149 i = *(p++);
@@ -152,17 +152,17 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
152 goto err; 152 goto err;
153 } 153 }
154 154
155 /* We do this to preserve the settings. If we modify 155 /*
156 * the settings, via the _set_bit function, we will recalculate 156 * We do this to preserve the settings. If we modify the settings,
157 * on output */ 157 * via the _set_bit function, we will recalculate on output.
158 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */ 158 */
159 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ 159 ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */
160 160 ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */
161 if (len-- > 1) /* using one because of the bits left byte */ 161
162 { 162 /* using one because of the bits left byte */
163 s = malloc(len); 163 if (len-- > 1) {
164 if (s == NULL) { 164 if ((s = malloc(len)) == NULL) {
165 i = ERR_R_MALLOC_FAILURE; 165 ASN1error(ERR_R_MALLOC_FAILURE);
166 goto err; 166 goto err;
167 } 167 }
168 memcpy(s, p, len); 168 memcpy(s, p, len);
@@ -171,19 +171,22 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
171 } else 171 } else
172 s = NULL; 172 s = NULL;
173 173
174 ret->length = (int)len;
175 free(ret->data); 174 free(ret->data);
176 ret->data = s; 175 ret->data = s;
176 ret->length = (int)len;
177 ret->type = V_ASN1_BIT_STRING; 177 ret->type = V_ASN1_BIT_STRING;
178
178 if (a != NULL) 179 if (a != NULL)
179 (*a) = ret; 180 *a = ret;
181
180 *pp = p; 182 *pp = p;
183
181 return (ret); 184 return (ret);
182 185
183err: 186 err:
184 ASN1error(i); 187 if (a == NULL || *a != ret)
185 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
186 ASN1_BIT_STRING_free(ret); 188 ASN1_BIT_STRING_free(ret);
189
187 return (NULL); 190 return (NULL);
188} 191}
189 192