aboutsummaryrefslogtreecommitdiff
path: root/crypto/asn1/f_string.c
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2017-08-21 07:19:17 +1000
committerPauli <paul.dale@oracle.com>2017-08-22 09:45:25 +1000
commita1df06b36347a31c17d09e6ca3e1464bdf7eb4d5 (patch)
treebeb260df46896a5c8668dd7f64c5dcefe677b1e6 /crypto/asn1/f_string.c
parent00dfbaad88a69ed8294d6039bf5f7d722f72bf39 (diff)
downloadopenssl-a1df06b36347a31c17d09e6ca3e1464bdf7eb4d5.zip
openssl-a1df06b36347a31c17d09e6ca3e1464bdf7eb4d5.tar.gz
openssl-a1df06b36347a31c17d09e6ca3e1464bdf7eb4d5.tar.bz2
This has been added to avoid the situation where some host ctype.h functions
return true for characters > 127. I.e. they are allowing extended ASCII characters through which then cause problems. E.g. marking superscript '2' as a number then causes the common (ch - '0') conversion to number to fail miserably. Likewise letters with diacritical marks can also cause problems. If a non-ASCII character set is being used (currently only EBCDIC), it is adjusted for. The implementation uses a single table with a bit for each of the defined classes. These functions accept an int argument and fail for values out of range or for characters outside of the ASCII set. They will work for both signed and unsigned character inputs. Reviewed-by: Andy Polyakov <appro@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4102)
Diffstat (limited to 'crypto/asn1/f_string.c')
-rw-r--r--crypto/asn1/f_string.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/crypto/asn1/f_string.c b/crypto/asn1/f_string.c
index b9258bb..cfb895f 100644
--- a/crypto/asn1/f_string.c
+++ b/crypto/asn1/f_string.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -8,7 +8,7 @@
*/
#include <stdio.h>
-#include <ctype.h>
+#include "internal/ctype.h"
#include "internal/cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/asn1.h>
@@ -47,7 +47,7 @@ int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type)
int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
{
- int i, j, k, m, n, again, bufsize, spec_char;
+ int i, j, k, m, n, again, bufsize;
unsigned char *s = NULL, *sp;
unsigned char *bufp;
int num = 0, slen = 0, first = 1;
@@ -74,19 +74,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
again = (buf[i - 1] == '\\');
for (j = i - 1; j > 0; j--) {
-#ifndef CHARSET_EBCDIC
- spec_char = (!(((buf[j] >= '0') && (buf[j] <= '9')) ||
- ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
- ((buf[j] >= 'A') && (buf[j] <= 'F'))));
-#else
- /*
- * This #ifdef is not strictly necessary, since the characters
- * A...F a...f 0...9 are contiguous (yes, even in EBCDIC - but
- * not the whole alphabet). Nevertheless, isxdigit() is faster.
- */
- spec_char = (!isxdigit(buf[j]));
-#endif
- if (spec_char) {
+ if (!ossl_isxdigit(buf[j])) {
i = j;
break;
}