From 0ee7a6d75ed0a1890d8cd124979f1e2b2cdd0f2d Mon Sep 17 00:00:00 2001 From: Richard T Bonhomme Date: Sun, 20 Nov 2022 13:37:47 +0000 Subject: [PATCH] Minor refactor: escape_hazard() Squashed commit of the following: commit 81937721412478c0f4b7d32b6a55d18099608d88 Merge: 43d7648 345e6cc Author: Richard T Bonhomme Date: Sun Nov 20 13:37:05 2022 +0000 Merge branch 'improve-escape_hazard' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-improve-escape_hazard Signed-off-by: Richard T Bonhomme commit 345e6cc5540d411e32c3cc7ced3017742188d144 Author: Richard T Bonhomme Date: Sun Nov 20 13:07:37 2022 +0000 Minor refactor: escape_hazard() Remove development code. Improve text. Signed-off-by: Richard T Bonhomme Signed-off-by: Richard T Bonhomme --- easyrsa3/easyrsa | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/easyrsa3/easyrsa b/easyrsa3/easyrsa index f9e4850..20321dc 100755 --- a/easyrsa3/easyrsa +++ b/easyrsa3/easyrsa @@ -760,27 +760,23 @@ make_safe_ssl_copy() { # Escape hazardous characters escape_hazard() { - # escape '&' and '$' and write free form fields to org temp-file - ( # subshell for local debug - # debug log on - if [ "$EASYRSA_DEBUG" ]; then print "<< DEBUG-ON >>"; set -x; fi - print "\ + # write org fields to org temp-file and escape '&' and '$' + print "\ export EASYRSA_REQ_COUNTRY=\"$EASYRSA_REQ_COUNTRY\" export EASYRSA_REQ_PROVINCE=\"$EASYRSA_REQ_PROVINCE\" export EASYRSA_REQ_CITY=\"$EASYRSA_REQ_CITY\" export EASYRSA_REQ_ORG=\"$EASYRSA_REQ_ORG\" export EASYRSA_REQ_OU=\"$EASYRSA_REQ_OU\" export EASYRSA_REQ_EMAIL=\"$EASYRSA_REQ_EMAIL\" -" | sed -e s\`'&'\`'\\\&'\`g \ - -e s\`'\$'\`'\\\$'\`g > "$easyrsa_openssl_conf_org" || \ - die "Failed to write 'easyrsa_openssl_conf_org' temp file" - # debug log off - if [ "$EASYRSA_DEBUG" ]; then set +x; print ">> DEBUG-OFF <<"; fi - ) # Close subshell +" | sed -e s\`'\&'\`'\\\&'\`g \ + -e s\`'\$'\`'\\\$'\`g \ + > "$easyrsa_openssl_conf_org" || die "\ +escape_hazard - Failed to write temp-file" - # Reload fields from fully escaped org temp-file + # Reload fields from fully escaped temp-file # shellcheck disable=SC1090 # can't follow non-constant source. - . "$easyrsa_openssl_conf_org" || die "escape_hazard - Failed to source 'org'" + . "$easyrsa_openssl_conf_org" || die "\ +escape_hazard - Failed to source temp-file" # Clean up rm -f "$easyrsa_openssl_conf_org"