summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinoguchi <>2020-02-17 12:51:48 +0000
committerinoguchi <>2020-02-17 12:51:48 +0000
commit63f370da2a67eb9d27cc1ec17bdf5c52ed842a43 (patch)
treecf2d0e5e749794ce2dc2a14dd681d4699b56e112
parent1063aaa9b7543a856d9a9d5695ced92c74ca1d76 (diff)
downloadopenbsd-63f370da2a67eb9d27cc1ec17bdf5c52ed842a43.tar.gz
openbsd-63f370da2a67eb9d27cc1ec17bdf5c52ed842a43.tar.bz2
openbsd-63f370da2a67eb9d27cc1ec17bdf5c52ed842a43.zip
Restrict the length of openssl conf value string
There was no limitation for the length of openssl conf value. This brings possibility of out-of-memory problem as oss-fuzz had detected. This diff restricts the length of conf value up to 64k. ok jsing@
-rw-r--r--src/lib/libcrypto/conf/conf.h3
-rw-r--r--src/lib/libcrypto/conf/conf_def.c13
-rw-r--r--src/lib/libcrypto/conf/conf_err.c3
3 files changed, 14 insertions, 5 deletions
diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h
index 095066d31b..bea6a87197 100644
--- a/src/lib/libcrypto/conf/conf.h
+++ b/src/lib/libcrypto/conf/conf.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf.h,v 1.14 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: conf.h,v 1.15 2020/02/17 12:51:48 inoguchi 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 *
@@ -241,6 +241,7 @@ void ERR_load_CONF_strings(void);
241#define CONF_R_NO_VALUE 108 241#define CONF_R_NO_VALUE 108
242#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 242#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
243#define CONF_R_UNKNOWN_MODULE_NAME 113 243#define CONF_R_UNKNOWN_MODULE_NAME 113
244#define CONF_R_VARIABLE_EXPANSION_TOO_LONG 116
244#define CONF_R_VARIABLE_HAS_NO_VALUE 104 245#define CONF_R_VARIABLE_HAS_NO_VALUE 104
245 246
246#ifdef __cplusplus 247#ifdef __cplusplus
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c
index 4099ffc66c..f2b2c9477b 100644
--- a/src/lib/libcrypto/conf/conf_def.c
+++ b/src/lib/libcrypto/conf/conf_def.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_def.c,v 1.32 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: conf_def.c,v 1.33 2020/02/17 12:51:48 inoguchi 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 *
@@ -70,6 +70,8 @@
70 70
71#include "conf_def.h" 71#include "conf_def.h"
72 72
73#define MAX_CONF_VALUE_LENGTH 65536
74
73static char *eat_ws(CONF *conf, char *p); 75static char *eat_ws(CONF *conf, char *p);
74static char *eat_alpha_numeric(CONF *conf, char *p); 76static char *eat_alpha_numeric(CONF *conf, char *p);
75static void clear_comments(CONF *conf, char *p); 77static void clear_comments(CONF *conf, char *p);
@@ -455,6 +457,7 @@ str_copy(CONF *conf, char *section, char **pto, char *from)
455{ 457{
456 int q, r,rr = 0, to = 0, len = 0; 458 int q, r,rr = 0, to = 0, len = 0;
457 char *s, *e, *rp, *p, *rrp, *np, *cp, v; 459 char *s, *e, *rp, *p, *rrp, *np, *cp, v;
460 size_t newsize;
458 BUF_MEM *buf; 461 BUF_MEM *buf;
459 462
460 if ((buf = BUF_MEM_new()) == NULL) 463 if ((buf = BUF_MEM_new()) == NULL)
@@ -563,8 +566,12 @@ str_copy(CONF *conf, char *section, char **pto, char *from)
563 CONFerror(CONF_R_VARIABLE_HAS_NO_VALUE); 566 CONFerror(CONF_R_VARIABLE_HAS_NO_VALUE);
564 goto err; 567 goto err;
565 } 568 }
566 if (!BUF_MEM_grow_clean(buf, 569 newsize = strlen(p) + buf->length - (e - from);
567 (strlen(p) + buf->length - (e - from)))) { 570 if (newsize > MAX_CONF_VALUE_LENGTH) {
571 CONFerror(CONF_R_VARIABLE_EXPANSION_TOO_LONG);
572 goto err;
573 }
574 if (!BUF_MEM_grow_clean(buf, newsize)) {
568 CONFerror(CONF_R_MODULE_INITIALIZATION_ERROR); 575 CONFerror(CONF_R_MODULE_INITIALIZATION_ERROR);
569 goto err; 576 goto err;
570 } 577 }
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
index dbb373ae85..1e5eaff60e 100644
--- a/src/lib/libcrypto/conf/conf_err.c
+++ b/src/lib/libcrypto/conf/conf_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_err.c,v 1.13 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: conf_err.c,v 1.14 2020/02/17 12:51:48 inoguchi Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -92,6 +92,7 @@ static ERR_STRING_DATA CONF_str_reasons[]= {
92 {ERR_REASON(CONF_R_NO_VALUE) , "no value"}, 92 {ERR_REASON(CONF_R_NO_VALUE) , "no value"},
93 {ERR_REASON(CONF_R_UNABLE_TO_CREATE_NEW_SECTION), "unable to create new section"}, 93 {ERR_REASON(CONF_R_UNABLE_TO_CREATE_NEW_SECTION), "unable to create new section"},
94 {ERR_REASON(CONF_R_UNKNOWN_MODULE_NAME) , "unknown module name"}, 94 {ERR_REASON(CONF_R_UNKNOWN_MODULE_NAME) , "unknown module name"},
95 {ERR_REASON(CONF_R_VARIABLE_EXPANSION_TOO_LONG), "variable expansion too long"},
95 {ERR_REASON(CONF_R_VARIABLE_HAS_NO_VALUE), "variable has no value"}, 96 {ERR_REASON(CONF_R_VARIABLE_HAS_NO_VALUE), "variable has no value"},
96 {0, NULL} 97 {0, NULL}
97}; 98};