Skip to content

Commit 198c18d

Browse files
committed
Cleanups for bandit
Set bandit to ignore use of md5. Treat schema from database as trusted to eval. We wrote it based on the schema.py file. Replace some bare except: with a proper exception. mode 775 for index directory is correct. Allows indices to be written by email and web interfaces that run as different users but can have the roundup group in common.
1 parent acdbde2 commit 198c18d

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

roundup/backends/back_anydbm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ def get(self, nodeid, propname, default=_marker, cache=1):
22172217
# calculation of the object.
22182218
return ('%s%s is not text, retrieve using '
22192219
'binary_content property. mdsum: %s')%(self.classname,
2220-
nodeid, md5(self.db.getfile(self.classname, nodeid, None)).hexdigest())
2220+
nodeid, md5(self.db.getfile(self.classname, nodeid, None)).hexdigest()) # nosec - bandit md5 use ok
22212221
elif propname == 'binary_content':
22222222
return self.db.getfile(self.classname, nodeid, None)
22232223

roundup/backends/back_mysql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def db_nuke(config):
6565
conn = MySQLdb.connect(**kwargs)
6666
try:
6767
conn.select_db(config.RDBMS_NAME)
68-
except:
68+
except MySQLdb.Error:
6969
# no, it doesn't exist
7070
pass
7171
else:
@@ -203,7 +203,8 @@ def load_dbschema(self):
203203
self.cursor.execute('select `schema` from `schema`')
204204
schema = self.cursor.fetchone()
205205
if schema:
206-
self.database_schema = eval(schema[0])
206+
# bandit - schema is trusted
207+
self.database_schema = eval(schema[0]) # nosec
207208
else:
208209
self.database_schema = {}
209210

roundup/backends/blobfiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def filename(self, classname, nodeid, property=None, create=0):
282282
try:
283283
# Clean up, by performing the commit now.
284284
os.rename(tempfile, filename)
285-
except:
285+
except OSError:
286286
pass
287287
# If two Roundup clients both try to rename the file
288288
# at the same time, only one of them will succeed.

roundup/backends/indexer_dbm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def force_reindex(self):
6262
if os.path.exists(self.indexdb_path):
6363
shutil.rmtree(self.indexdb_path)
6464
os.makedirs(self.indexdb_path)
65-
os.chmod(self.indexdb_path, 0o775)
65+
os.chmod(self.indexdb_path, 0o775) # nosec - allow group write
6666
open(os.path.join(self.indexdb_path, 'version'), 'w').write('1\n')
6767
self.reindex = 1
6868
self.changed = 1

roundup/backends/rdbms_common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _num_cvt(num):
8080
num = str(num)
8181
try:
8282
return int(num)
83-
except:
83+
except ValueError:
8484
return float(num)
8585

8686
def _bool_cvt(value):
@@ -273,7 +273,8 @@ def load_dbschema(self):
273273
self.cursor.execute('select schema from schema')
274274
schema = self.cursor.fetchone()
275275
if schema:
276-
self.database_schema = eval(schema[0])
276+
# bandit - schema is trusted
277+
self.database_schema = eval(schema[0]) # nosec
277278
else:
278279
self.database_schema = {}
279280

@@ -672,7 +673,7 @@ def add_class_key_required_unique_constraint(self, cn, key):
672673
on _%s(__retired__, _%s)'''%(cn, cn, key)
673674
try:
674675
self.sql(sql)
675-
except Exception:
676+
except Exception: # nosec
676677
# XXX catch e.g.:
677678
# _sqlite.DatabaseError: index _status_key_retired_idx already exists
678679
pass
@@ -3117,7 +3118,7 @@ def get(self, nodeid, propname, default=_marker, cache=1):
31173118
# calculation of the object.
31183119
return ('%s%s is not text, retrieve using '
31193120
'binary_content property. mdsum: %s')%(self.classname,
3120-
nodeid, md5(self.db.getfile(self.classname, nodeid, None)).hexdigest())
3121+
nodeid, md5(self.db.getfile(self.classname, nodeid, None)).hexdigest()) # nosec - bandit md5 use ok
31213122
elif propname == 'binary_content':
31223123
return self.db.getfile(self.classname, nodeid, None)
31233124

0 commit comments

Comments
 (0)