summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorschwarze <>2021-11-19 09:58:41 +0000
committerschwarze <>2021-11-19 09:58:41 +0000
commita6de8aaa10fec4627b88369c4c72b0667de753da (patch)
treead88b0fd54c80f12d6a499dedf95ad711028244f /src/lib
parentca49b82866e22619b5b7a9bdbef2328b7adeff11 (diff)
downloadopenbsd-a6de8aaa10fec4627b88369c4c72b0667de753da.tar.gz
openbsd-a6de8aaa10fec4627b88369c4c72b0667de753da.tar.bz2
openbsd-a6de8aaa10fec4627b88369c4c72b0667de753da.zip
Make the public API function a2i_ASN1_STRING(3) actually work.
It contained two bugs: 1. If an input line ended in a backslash requesting line continuation, there was duplicate code for removing that backslash, erroneously removing another byte from the input and often causing the function to return failure instead of correctly parsing valid input. 2. According to a comment in the source code, the former big "for" loop was intended to "clear all the crap off the end of the line", but actually, if there were multiple characters on the line that were not hexadecimal digits, only the last of those and everything following it was deleted, while all the earlier ones remained. Besides, code further down clearly intends to error out when there are invalid characters, which makes no sense if earlier code already deletes such characters. Hence the comment did not only contradict the code above it - but contradicted the code below it, too. Resolve these contradiction in favour of stricter parsing: No longer skip invalid characters but always error out when any are found. OK & "Unbelievable" tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/asn1/f_string.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
index af17f43e1d..b34343db39 100644
--- a/src/lib/libcrypto/asn1/f_string.c
+++ b/src/lib/libcrypto/asn1/f_string.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: f_string.c,v 1.18 2018/04/25 11:48:21 tb Exp $ */ 1/* $OpenBSD: f_string.c,v 1.19 2021/11/19 09:58:41 schwarze 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 *
@@ -125,26 +125,18 @@ a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
125 buf[--i] = '\0'; 125 buf[--i] = '\0';
126 if (i == 0) 126 if (i == 0)
127 goto err_sl; 127 goto err_sl;
128 again = (buf[i - 1] == '\\'); 128 if (buf[i - 1] == '\\') {
129 129 i--;
130 for (j = i - 1; j > 0; j--) { 130 again = 1;
131 if (!(((buf[j] >= '0') && (buf[j] <= '9')) || 131 } else
132 ((buf[j] >= 'a') && (buf[j] <= 'f')) || 132 again = 0;
133 ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
134 i = j;
135 break;
136 }
137 }
138 buf[i] = '\0'; 133 buf[i] = '\0';
139 /* We have now cleared all the crap off the end of the
140 * line */
141 if (i < 2) 134 if (i < 2)
142 goto err_sl; 135 goto err_sl;
143 136
144 bufp = (unsigned char *)buf; 137 bufp = (unsigned char *)buf;
145 138
146 k = 0; 139 k = 0;
147 i -= again;
148 if (i % 2 != 0) { 140 if (i % 2 != 0) {
149 ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS); 141 ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
150 goto err; 142 goto err;