use yaml.safe_{load,dump} functions

The yaml.load() function can run arbitrary code, the safe_load() variant only
understands a safe subset of YAML which is enough for dak.
上级 9577d0bf
...@@ -41,7 +41,7 @@ from os import listdir, system, unlink ...@@ -41,7 +41,7 @@ from os import listdir, system, unlink
from os.path import isfile, join, splitext from os.path import isfile, join, splitext
from re import findall, DOTALL, MULTILINE from re import findall, DOTALL, MULTILINE
from sys import stderr from sys import stderr
from yaml import load, safe_dump from yaml import safe_load, safe_dump
from daklib import utils from daklib import utils
from daklib.dbconn import DBConn, get_suite_architectures, Suite, Architecture from daklib.dbconn import DBConn, get_suite_architectures, Suite, Architecture
...@@ -340,7 +340,7 @@ def new_stats(logdir, yaml): ...@@ -340,7 +340,7 @@ def new_stats(logdir, yaml):
global stats global stats
try: try:
with open(yaml, 'r') as fd: with open(yaml, 'r') as fd:
stats = load(fd) stats = safe_load(fd)
except IOError: except IOError:
pass pass
if not stats: if not stats:
......
...@@ -134,7 +134,7 @@ def load_transitions(trans_file): ...@@ -134,7 +134,7 @@ def load_transitions(trans_file):
sourcecontent = sourcefile.read() sourcecontent = sourcefile.read()
failure = False failure = False
try: try:
trans = yaml.load(sourcecontent) trans = yaml.safe_load(sourcecontent)
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
# Someone fucked it up # Someone fucked it up
print "ERROR: %s" % (exc) print "ERROR: %s" % (exc)
...@@ -262,7 +262,7 @@ def write_transitions(from_trans): ...@@ -262,7 +262,7 @@ def write_transitions(from_trans):
temp_lock = lock_file(trans_temp) temp_lock = lock_file(trans_temp)
destfile = file(trans_temp, 'w') destfile = file(trans_temp, 'w')
yaml.dump(from_trans, destfile, default_flow_style=False) yaml.safe_dump(from_trans, destfile, default_flow_style=False)
destfile.close() destfile.close()
os.rename(trans_temp, trans_file) os.rename(trans_temp, trans_file)
...@@ -321,7 +321,7 @@ def temp_transitions_file(transitions): ...@@ -321,7 +321,7 @@ def temp_transitions_file(transitions):
(fd, path) = tempfile.mkstemp("", "transitions", Cnf["Dir::TempPath"]) (fd, path) = tempfile.mkstemp("", "transitions", Cnf["Dir::TempPath"])
os.chmod(path, 0o644) os.chmod(path, 0o644)
f = open(path, "w") f = open(path, "w")
yaml.dump(transitions, f, default_flow_style=False) yaml.safe_dump(transitions, f, default_flow_style=False)
return path return path
################################################################################ ################################################################################
......
...@@ -602,7 +602,7 @@ transition is done.""".format(source, currentlymsg, expected,t["rm"]))) ...@@ -602,7 +602,7 @@ transition is done.""".format(source, currentlymsg, expected,t["rm"])))
contents = file(path, 'r').read() contents = file(path, 'r').read()
try: try:
transitions = yaml.load(contents) transitions = yaml.safe_load(contents)
return transitions return transitions
except yaml.YAMLError as msg: except yaml.YAMLError as msg:
utils.warn('Not checking transitions, the transitions file is broken: {0}'.format(msg)) utils.warn('Not checking transitions, the transitions file is broken: {0}'.format(msg))
...@@ -643,7 +643,7 @@ class LintianCheck(Check): ...@@ -643,7 +643,7 @@ class LintianCheck(Check):
with open(tagfile, 'r') as sourcefile: with open(tagfile, 'r') as sourcefile:
sourcecontent = sourcefile.read() sourcecontent = sourcefile.read()
try: try:
lintiantags = yaml.load(sourcecontent)['lintian'] lintiantags = yaml.safe_load(sourcecontent)['lintian']
except yaml.YAMLError as msg: except yaml.YAMLError as msg:
raise Exception('Could not read lintian tags file {0}, YAML error: {1}'.format(tagfile, msg)) raise Exception('Could not read lintian tags file {0}, YAML error: {1}'.format(tagfile, msg))
......
...@@ -41,8 +41,6 @@ from types import * ...@@ -41,8 +41,6 @@ from types import *
from sqlalchemy.sql.expression import desc from sqlalchemy.sql.expression import desc
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
import yaml
from dak_exceptions import * from dak_exceptions import *
from changes import * from changes import *
from regexes import * from regexes import *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册