1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 17:00:12 +01:00

Always check that files actually are files before reading

This fixes crashes with e.g. broken symlinks
This commit is contained in:
Daniel Martí 2015-04-03 00:05:22 +02:00
parent 85b48a5c25
commit 241a3f02ac

View File

@ -875,6 +875,8 @@ def retrieve_string(app_dir, string, xmlfiles=None):
if string_search is not None: if string_search is not None:
for xmlfile in xmlfiles: for xmlfile in xmlfiles:
if not os.path.isfile(xmlfile):
continue
for line in file(xmlfile): for line in file(xmlfile):
matches = string_search(line) matches = string_search(line)
if matches: if matches:
@ -908,7 +910,7 @@ def fetch_real_name(app_dir, flavours):
name_search = re.compile(r'.*android:label="([^"]+)".*').search name_search = re.compile(r'.*android:label="([^"]+)".*').search
app_found = False app_found = False
for f in manifest_paths(app_dir, flavours): for f in manifest_paths(app_dir, flavours):
if not has_extension(f, 'xml'): if not has_extension(f, 'xml') or not os.path.isfile(f):
continue continue
logging.debug("fetch_real_name: Checking manifest at " + f) logging.debug("fetch_real_name: Checking manifest at " + f)
for line in file(f): for line in file(f):
@ -1002,6 +1004,9 @@ def parse_androidmanifests(paths, ignoreversions=None):
for path in paths: for path in paths:
if not os.path.isfile(path):
continue
logging.debug("Parsing manifest at {0}".format(path)) logging.debug("Parsing manifest at {0}".format(path))
gradle = has_extension(path, 'gradle') gradle = has_extension(path, 'gradle')
version = None version = None
@ -1580,7 +1585,7 @@ def scan_source(build_dir, root_dir, thisbuild):
else: else:
warnproblem('unknown compressed or binary file', fd) warnproblem('unknown compressed or binary file', fd)
elif has_extension(fp, 'java'): elif has_extension(fp, 'java') and os.path.isfile(fp):
for line in file(fp): for line in file(fp):
if 'DexClassLoader' in line: if 'DexClassLoader' in line:
count += handleproblem('DexClassLoader', fd, fp) count += handleproblem('DexClassLoader', fd, fp)
@ -1614,7 +1619,7 @@ class KnownApks:
def __init__(self): def __init__(self):
self.path = os.path.join('stats', 'known_apks.txt') self.path = os.path.join('stats', 'known_apks.txt')
self.apks = {} self.apks = {}
if os.path.exists(self.path): if os.path.isfile(self.path):
for line in file(self.path): for line in file(self.path):
t = line.rstrip().split(' ') t = line.rstrip().split(' ')
if len(t) == 2: if len(t) == 2: