summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_mbstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/a_mbstr.c')
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
index 7a710d5459..5d981c6553 100644
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -92,6 +92,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
92{ 92{
93 int str_type; 93 int str_type;
94 int ret; 94 int ret;
95 char free_out;
95 int outform, outlen; 96 int outform, outlen;
96 ASN1_STRING *dest; 97 ASN1_STRING *dest;
97 unsigned char *p; 98 unsigned char *p;
@@ -180,14 +181,16 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
180 } 181 }
181 if(!out) return str_type; 182 if(!out) return str_type;
182 if(*out) { 183 if(*out) {
184 free_out = 0;
183 dest = *out; 185 dest = *out;
184 if(dest->data) { 186 if(dest->data) {
185 dest->length = 0; 187 dest->length = 0;
186 Free(dest->data); 188 OPENSSL_free(dest->data);
187 dest->data = NULL; 189 dest->data = NULL;
188 } 190 }
189 dest->type = str_type; 191 dest->type = str_type;
190 } else { 192 } else {
193 free_out = 1;
191 dest = ASN1_STRING_type_new(str_type); 194 dest = ASN1_STRING_type_new(str_type);
192 if(!dest) { 195 if(!dest) {
193 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, 196 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
@@ -228,8 +231,8 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
228 cpyfunc = cpy_utf8; 231 cpyfunc = cpy_utf8;
229 break; 232 break;
230 } 233 }
231 if(!(p = Malloc(outlen + 1))) { 234 if(!(p = OPENSSL_malloc(outlen + 1))) {
232 ASN1_STRING_free(dest); 235 if(free_out) ASN1_STRING_free(dest);
233 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE); 236 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
234 return -1; 237 return -1;
235 } 238 }
@@ -258,8 +261,8 @@ static int traverse_string(const unsigned char *p, int len, int inform,
258 value |= *p++; 261 value |= *p++;
259 len -= 2; 262 len -= 2;
260 } else if(inform == MBSTRING_UNIV) { 263 } else if(inform == MBSTRING_UNIV) {
261 value = *p++ << 24; 264 value = ((unsigned long)*p++) << 24;
262 value |= *p++ << 16; 265 value |= ((unsigned long)*p++) << 16;
263 value |= *p++ << 8; 266 value |= *p++ << 8;
264 value |= *p++; 267 value |= *p++;
265 len -= 4; 268 len -= 4;
@@ -382,9 +385,16 @@ static int is_printable(unsigned long value)
382 /* Note: we can't use 'isalnum' because certain accented 385 /* Note: we can't use 'isalnum' because certain accented
383 * characters may count as alphanumeric in some environments. 386 * characters may count as alphanumeric in some environments.
384 */ 387 */
388#ifndef CHARSET_EBCDIC
385 if((ch >= 'a') && (ch <= 'z')) return 1; 389 if((ch >= 'a') && (ch <= 'z')) return 1;
386 if((ch >= 'A') && (ch <= 'Z')) return 1; 390 if((ch >= 'A') && (ch <= 'Z')) return 1;
387 if((ch >= '0') && (ch <= '9')) return 1; 391 if((ch >= '0') && (ch <= '9')) return 1;
388 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1; 392 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
393#else /*CHARSET_EBCDIC*/
394 if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1;
395 if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1;
396 if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1;
397 if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1;
398#endif /*CHARSET_EBCDIC*/
389 return 0; 399 return 0;
390} 400}