re-align these copies of the a2i_*(3) code with f_string.c rev. 1.19
authorschwarze <schwarze@openbsd.org>
Tue, 23 Nov 2021 11:10:51 +0000 (11:10 +0000)
committerschwarze <schwarze@openbsd.org>
Tue, 23 Nov 2021 11:10:51 +0000 (11:10 +0000)
to fix the same double-counting of the backslash
and to make the parsing stricter in the same way;
OK tb@

lib/libcrypto/asn1/f_enum.c
lib/libcrypto/asn1/f_int.c

index cc4b7df..e525670 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: f_enum.c,v 1.16 2018/04/25 11:48:21 tb Exp $ */
+/* $OpenBSD: f_enum.c,v 1.17 2021/11/23 11:10:51 schwarze Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -123,19 +123,12 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
                        buf[--i] = '\0';
                if (i == 0)
                        goto err_sl;
-               again = (buf[i - 1] == '\\');
-
-               for (j = 0; j < i; j++) {
-                       if (!(((buf[j] >= '0') && (buf[j] <= '9')) ||
-                           ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
-                           ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
-                               i = j;
-                               break;
-                       }
-               }
+               if (buf[i - 1] == '\\') {
+                       i--;
+                       again = 1;
+               } else
+                       again = 0;
                buf[i] = '\0';
-               /* We have now cleared all the crap off the end of the
-                * line */
                if (i < 2)
                        goto err_sl;
 
@@ -148,7 +141,6 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
                        }
                }
                k = 0;
-               i -= again;
                if (i % 2 != 0) {
                        ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
                        goto err;
index d03fafe..8ce9d20 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: f_int.c,v 1.20 2018/05/13 13:48:08 jsing Exp $ */
+/* $OpenBSD: f_int.c,v 1.21 2021/11/23 11:10:51 schwarze Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -126,19 +126,12 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
                        buf[--i] = '\0';
                if (i == 0)
                        goto err_sl;
-               again = (buf[i - 1] == '\\');
-
-               for (j = 0; j < i; j++) {
-                       if (!(((buf[j] >= '0') && (buf[j] <= '9')) ||
-                           ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
-                           ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
-                               i = j;
-                               break;
-                       }
-               }
+               if (buf[i - 1] == '\\') {
+                       i--;
+                       again = 1;
+               } else
+                       again = 0;
                buf[i] = '\0';
-               /* We have now cleared all the crap off the end of the
-                * line */
                if (i < 2)
                        goto err_sl;
 
@@ -151,7 +144,6 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
                        }
                }
                k = 0;
-               i -= again;
                if (i % 2 != 0) {
                        ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
                        goto err;