From a1d4eac64db4a9d6776f3de9b39d2a64f8417b24 Mon Sep 17 00:00:00 2001 From: David Cooper Date: Mon, 10 Apr 2017 17:07:46 -0400 Subject: [PATCH 1/2] Don't read tls_data.txt inside function I was doing some testing on my extended_tls_sockets branch and discovered that it was not fully working since the `TLS13_KEY_SHARES` array was empty. According to https://lists.gnu.org/archive/html/bug-bash/2012-06/msg00068.html, there is an issue when trying to initialize a global array inside a function. (The current code initializes `TLS12_CIPHER`, `TLS_CIPHER`, and `TLS13_KEY_SHARES` within `get_install_dir()`, since tls_data.txt is read in that function.) In fact, according to http://stackoverflow.com/questions/10806357/associative-arrays-are-local-by-default, in order to initialize a global variable in a function, one needs to provide the `-g` option, which was only added in Bash 4.2. This PR seems to fix the problem by moving the reading of tls_data.txt to the main body of the code rather than reading it within the `get_install_dir()` function. --- testssl.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testssl.sh b/testssl.sh index e9e5646..8b11faa 100755 --- a/testssl.sh +++ b/testssl.sh @@ -10385,8 +10385,6 @@ get_install_dir() { outln ignore_no_or_lame "Type \"yes\" to ignore this warning and proceed at your own risk" "yes" [[ $? -ne 0 ]] && exit -2 - else - . $TLS_DATA_FILE fi } @@ -12451,6 +12449,7 @@ lets_roll() { json_header csv_header get_install_dir + [[ -r "$TLS_DATA_FILE" ]] && . $TLS_DATA_FILE set_color_functions maketempf find_openssl_binary From ed2aa6698ddf0c37fe07ec404c3b1a7f2ce3c6fb Mon Sep 17 00:00:00 2001 From: Dirk Date: Tue, 11 Apr 2017 18:48:23 +0200 Subject: [PATCH 2/2] comments added for #705 --- testssl.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testssl.sh b/testssl.sh index 8b11faa..df1470f 100755 --- a/testssl.sh +++ b/testssl.sh @@ -10385,6 +10385,8 @@ get_install_dir() { outln ignore_no_or_lame "Type \"yes\" to ignore this warning and proceed at your own risk" "yes" [[ $? -ne 0 ]] && exit -2 + else + : # see #705, in a nutshell: not portable to initialize a global array inside a function. Thus it'll be done in main part below fi } @@ -12449,6 +12451,7 @@ lets_roll() { json_header csv_header get_install_dir + # see #705, we need to source TLS_DATA_FILE here instead of in get_install_dir(), see #705 [[ -r "$TLS_DATA_FILE" ]] && . $TLS_DATA_FILE set_color_functions maketempf