Skip to content

Commit 74eb8b2

Browse files
Issue python#22885: Fixed arbitrary code execution vulnerability in the dbm.dumb
module. Original patch by Claudiu Popa.
1 parent 57fffd6 commit 74eb8b2

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Lib/dbm/dumb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
"""
2323

24+
import ast as _ast
2425
import io as _io
2526
import os as _os
2627
import collections
@@ -85,7 +86,7 @@ def _update(self):
8586
with f:
8687
for line in f:
8788
line = line.rstrip()
88-
key, pos_and_siz_pair = eval(line)
89+
key, pos_and_siz_pair = _ast.literal_eval(line)
8990
key = key.encode('Latin-1')
9091
self._index[key] = pos_and_siz_pair
9192

Lib/test/test_dbm_dumb.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ def test_check_closed(self):
217217
self.assertEqual(str(cm.exception),
218218
"DBM object has already been closed")
219219

220+
def test_eval(self):
221+
with open(_fname + '.dir', 'w') as stream:
222+
stream.write("str(print('Hacked!')), 0\n")
223+
with support.captured_stdout() as stdout:
224+
with self.assertRaises(ValueError):
225+
with dumbdbm.open(_fname) as f:
226+
pass
227+
self.assertEqual(stdout.getvalue(), '')
228+
220229
def tearDown(self):
221230
_delete_files()
222231

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #22885: Fixed arbitrary code execution vulnerability in the dbm.dumb
17+
module. Original patch by Claudiu Popa.
18+
1619
- Issue #23146: Fix mishandling of absolute Windows paths with forward
1720
slashes in pathlib.
1821

0 commit comments

Comments
 (0)