Skip to content

Commit 9f92b0f

Browse files
committed
Quote command-line parameters
Fix #77
1 parent a5d6e88 commit 9f92b0f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

scheduler/app/database/init_db.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shlex
23
import time
34
import pymysql
45

@@ -42,16 +43,16 @@ def wait_for_mysql():
4243

4344
if db_user == "root":
4445
sql = 'mysql -h %s -u%s -p%s -e "CREATE DATABASE IF NOT EXISTS %s;"' % (
45-
DB_HOST,
46-
db_user,
47-
db_passwd,
46+
shlex.quote(DB_HOST),
47+
shlex.quote(db_user),
48+
shlex.quote(db_passwd),
4849
DATABASE_NAME,
4950
)
5051
os.system(sql)
5152
sql = "mysql -h %s -u%s -p%s %s </opt/scheduler/database/initial_tables.sql" % (
52-
DB_HOST,
53-
db_user,
54-
db_passwd,
53+
shlex.quote(DB_HOST),
54+
shlex.quote(db_user),
55+
shlex.quote(db_passwd),
5556
DATABASE_NAME,
5657
)
5758
os.system(sql)

scheduler/app/upgrade/upgrade.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import glob
99
import os
10+
import shlex
1011
from os.path import basename, join
1112
from sqlalchemy import text
1213
from datetime import datetime
@@ -79,11 +80,11 @@ def run_script_and_update_version_stamp(script, new_version):
7980
os.system(
8081
"mysql -h %(db_host)s -u%(db_user)s -p%(db_passwd)s %(database)s < %(script)s"
8182
% {
82-
"db_host": DB_HOST,
83-
"db_user": db_user,
84-
"db_passwd": db_passwd,
85-
"database": DATABASE_NAME,
86-
"script": script,
83+
"db_host": shlex.quote(DB_HOST),
84+
"db_user": shlex.quote(db_user),
85+
"db_passwd": shlex.quote(db_passwd),
86+
"database": shlex.quote(DATABASE_NAME),
87+
"script": shlex.quote(script),
8788
}
8889
)
8990
update_version_stamp(new_version)

0 commit comments

Comments
 (0)