summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2021-12-13 14:06:17 +0000
committerschwarze <>2021-12-13 14:06:17 +0000
commitff932a8c105e55b70f9248f6e57a9157c7969ef4 (patch)
tree2bdbb37033a308fca88214b0511427645872186d /src
parenteb7e84848bf9f5bb74cf5aaf96d14db842116c2d (diff)
downloadopenbsd-ff932a8c105e55b70f9248f6e57a9157c7969ef4.tar.gz
openbsd-ff932a8c105e55b70f9248f6e57a9157c7969ef4.tar.bz2
openbsd-ff932a8c105e55b70f9248f6e57a9157c7969ef4.zip
Catch integer overflow rather than silently truncating while
parsing MASK: strings in ASN1_STRING_set_default_mask_asc(3). Issue noticed by tb@, patch by me, two additional #include lines from tb@. OK tb@.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
index 08043f723b..f14daa602c 100644
--- a/src/lib/libcrypto/asn1/a_strnid.c
+++ b/src/lib/libcrypto/asn1/a_strnid.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_strnid.c,v 1.23 2021/12/11 22:58:48 schwarze Exp $ */ 1/* $OpenBSD: a_strnid.c,v 1.24 2021/12/13 14:06:17 schwarze Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -56,7 +56,10 @@
56 * 56 *
57 */ 57 */
58 58
59#include <errno.h>
60#include <limits.h>
59#include <stdio.h> 61#include <stdio.h>
62#include <stdlib.h>
60#include <string.h> 63#include <string.h>
61 64
62#include <openssl/asn1.h> 65#include <openssl/asn1.h>
@@ -106,11 +109,17 @@ ASN1_STRING_set_default_mask_asc(const char *p)
106{ 109{
107 unsigned long mask; 110 unsigned long mask;
108 char *end; 111 char *end;
112 int save_errno;
109 113
110 if (strncmp(p, "MASK:", 5) == 0) { 114 if (strncmp(p, "MASK:", 5) == 0) {
111 if (p[5] == '\0') 115 if (p[5] == '\0')
112 return 0; 116 return 0;
117 save_errno = errno;
118 errno = 0;
113 mask = strtoul(p + 5, &end, 0); 119 mask = strtoul(p + 5, &end, 0);
120 if (errno == ERANGE && mask == ULONG_MAX)
121 return 0;
122 errno = save_errno;
114 if (*end != '\0') 123 if (*end != '\0')
115 return 0; 124 return 0;
116 } else if (strcmp(p, "nombstr") == 0) 125 } else if (strcmp(p, "nombstr") == 0)