Skip to content

Commit aba5e60

Browse files
committed
Properly escape json in setup
1 parent aaccc14 commit aba5e60

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

‎debian/tvheadend.postinst‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ HTS_USER="hts"
55
. /usr/share/debconf/confmodule
66
db_version 2.0
77

8+
escape_json_string() {
9+
LANG=C command -p awk '
10+
BEGIN {
11+
ORS = ""
12+
13+
for ( i = 1; i <= 127; i++ )
14+
tr[ sprintf( "%c", i) ] = sprintf( "\\u%04x", i )
15+
16+
for ( i = 1; i < ARGC; i++ ) {
17+
s = ARGV[i]
18+
print "\""
19+
while ( match( s, /[\001-\037\177"\\]/ ) ) {
20+
print substr(s,1,RSTART-1) tr[ substr(s,RSTART,RLENGTH) ]
21+
s = substr(s,RSTART+RLENGTH)
22+
}
23+
print s "\"\n"
24+
}
25+
}
26+
' "$@"
27+
}
28+
829
case "$1" in
930
configure)
1031
if ! getent passwd "$HTS_USER" >/dev/null; then
@@ -36,11 +57,15 @@ configure)
3657
echo >>"$HTS_SUPERUSERCONF" "{"
3758

3859
if db_get tvheadend/admin_username; then
39-
echo >>"$HTS_SUPERUSERCONF" "\"username\": \"$RET\","
60+
JSONUSER=`escape_json_string $RET`
61+
echo "\"username\": $JSONUSER,"
62+
JSONUSER=""
4063
fi
4164

4265
if db_get tvheadend/admin_password; then
43-
echo >>"$HTS_SUPERUSERCONF" "\"password\": \"$RET\""
66+
JSONPASS=`escape_json_string $RET`
67+
echo "\"password\": $JSONPASS"
68+
JSONPASS=""
4469
fi
4570

4671
echo >>"$HTS_SUPERUSERCONF" "}"

0 commit comments

Comments
 (0)