]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Properly escape json in setup
authorFlole <Flole998@users.noreply.github.com>
Wed, 24 Apr 2024 14:29:14 +0000 (16:29 +0200)
committerFlole <Flole998@users.noreply.github.com>
Thu, 25 Apr 2024 20:57:37 +0000 (22:57 +0200)
debian/tvheadend.postinst

index eff115c9d41c4d4dc5df9b97965ef0012d574d64..652f311b3633a40821bcb2b4c2b1c2d40ea39c3e 100644 (file)
@@ -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" "}"