From: Flole Date: Wed, 24 Apr 2024 14:29:14 +0000 (+0200) Subject: Properly escape json in setup X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aba5e60792177d6a2a867445559f4806973b3258;p=thirdparty%2Ftvheadend.git Properly escape json in setup --- diff --git a/debian/tvheadend.postinst b/debian/tvheadend.postinst index eff115c9d..652f311b3 100644 --- a/debian/tvheadend.postinst +++ b/debian/tvheadend.postinst @@ -5,6 +5,27 @@ HTS_USER="hts" . /usr/share/debconf/confmodule db_version 2.0 +escape_json_string() { + LANG=C command -p awk ' + BEGIN { + ORS = "" + + for ( i = 1; i <= 127; i++ ) + tr[ sprintf( "%c", i) ] = sprintf( "\\u%04x", i ) + + for ( i = 1; i < ARGC; i++ ) { + s = ARGV[i] + print "\"" + while ( match( s, /[\001-\037\177"\\]/ ) ) { + print substr(s,1,RSTART-1) tr[ substr(s,RSTART,RLENGTH) ] + s = substr(s,RSTART+RLENGTH) + } + print s "\"\n" + } + } + ' "$@" +} + case "$1" in configure) if ! getent passwd "$HTS_USER" >/dev/null; then @@ -36,11 +57,15 @@ configure) echo >>"$HTS_SUPERUSERCONF" "{" if db_get tvheadend/admin_username; then - echo >>"$HTS_SUPERUSERCONF" "\"username\": \"$RET\"," + JSONUSER=`escape_json_string $RET` + echo "\"username\": $JSONUSER," + JSONUSER="" fi if db_get tvheadend/admin_password; then - echo >>"$HTS_SUPERUSERCONF" "\"password\": \"$RET\"" + JSONPASS=`escape_json_string $RET` + echo "\"password\": $JSONPASS" + JSONPASS="" fi echo >>"$HTS_SUPERUSERCONF" "}"