summaryrefslogtreecommitdiffstats
path: root/crypto/conf
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2021-04-29 22:22:30 +0200
committerTomas Mraz <tomas@openssl.org>2021-05-05 13:11:17 +0200
commit3fb985fd04611082bbfc3622a078e8c5e5edb378 (patch)
treef465217c2b35abf7f8e50bbf86d895ae2b6a5ee0 /crypto/conf
parentNote that dhparam does support X9.42 (diff)
downloadopenssl-3fb985fd04611082bbfc3622a078e8c5e5edb378.tar.xz
openssl-3fb985fd04611082bbfc3622a078e8c5e5edb378.zip
Allow absolute paths to be set
It was a mistake to allow relative paths for include files (just like root shouldn't have "." in its PATH), but we probably can't change it now. Add a new pragma "abspath" that someone can put in the system-wide config file to require absolute paths. Also update the config documentation to better explain how file inclusion works. Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15090)
Diffstat (limited to 'crypto/conf')
-rw-r--r--crypto/conf/conf_def.c35
-rw-r--r--crypto/conf/conf_err.c3
2 files changed, 28 insertions, 10 deletions
diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c
index bfb718753b..9561e2338a 100644
--- a/crypto/conf/conf_def.c
+++ b/crypto/conf/conf_def.c
@@ -188,6 +188,23 @@ static int def_load(CONF *conf, const char *name, long *line)
return ret;
}
+
+/* Parse a boolean value and fill in *flag. Return 0 on error. */
+static int parsebool(const char *pval, int *flag)
+{
+ if (strcmp(pval, "on") == 0
+ || strcmp(pval, "true") == 0) {
+ *flag = 1;
+ } else if (strcmp(pval, "off") == 0
+ || strcmp(pval, "false") == 0) {
+ *flag = 0;
+ } else {
+ ERR_raise(ERR_LIB_CONF, CONF_R_INVALID_PRAGMA);
+ return 0;
+ }
+ return 1;
+}
+
static int def_load_bio(CONF *conf, BIO *in, long *line)
{
/* The macro BUFSIZE conflicts with a system macro in VxWorks */
@@ -399,16 +416,11 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
* dollarid takes "on", "true or "off", "false"
*/
if (strcmp(p, "dollarid") == 0) {
- if (strcmp(pval, "on") == 0
- || strcmp(pval, "true") == 0) {
- conf->flag_dollarid = 1;
- } else if (strcmp(pval, "off") == 0
- || strcmp(pval, "false") == 0) {
- conf->flag_dollarid = 0;
- } else {
- ERR_raise(ERR_LIB_CONF, CONF_R_INVALID_PRAGMA);
+ if (!parsebool(pval, &conf->flag_dollarid))
+ goto err;
+ } else if (strcmp(p, "abspath") == 0) {
+ if (!parsebool(pval, &conf->flag_abspath))
goto err;
- }
}
/*
* We *ignore* any unknown pragma.
@@ -429,6 +441,11 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
if (!str_copy(conf, psection, &include, p))
goto err;
+ if (conf->flag_abspath && !ossl_is_absolute_path(include)) {
+ ERR_raise(ERR_LIB_CONF, CONF_R_RELATIVE_PATH);
+ goto err;
+ }
+
if (include_dir != NULL && !ossl_is_absolute_path(include)) {
size_t newlen = strlen(include_dir) + strlen(include) + 2;
diff --git a/crypto/conf/conf_err.c b/crypto/conf/conf_err.c
index 417ae58efb..a06f55b104 100644
--- a/crypto/conf/conf_err.c
+++ b/crypto/conf/conf_err.c
@@ -1,6 +1,6 @@
/*
* Generated by util/mkerr.pl DO NOT EDIT
- * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -41,6 +41,7 @@ static const ERR_STRING_DATA CONF_str_reasons[] = {
"openssl conf references missing section"},
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_RECURSIVE_DIRECTORY_INCLUDE),
"recursive directory include"},
+ {ERR_PACK(ERR_LIB_CONF, 0, CONF_R_RELATIVE_PATH), "relative path"},
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_SSL_COMMAND_SECTION_EMPTY),
"ssl command section empty"},
{ERR_PACK(ERR_LIB_CONF, 0, CONF_R_SSL_COMMAND_SECTION_NOT_FOUND),