mirror of
https://github.com/python/cpython.git
synced 2025-08-21 17:25:34 +00:00
Backport 58532, 58533, 58534:
- Fix bsddb.dbtables: Don't randomly corrupt newly inserted rows by picking a rowid string with null bytes in it. Such rows could not later be deleted, modified or individually selected. Existing bsdTableDb databases created with such rows are out of luck. - Use mkdtemp for the test_dbtables test database environment and clean it up afterwards using shutil.rmtree.
This commit is contained in:
parent
574e1ba814
commit
0dcc3cc949
3 changed files with 17 additions and 17 deletions
|
@ -20,7 +20,7 @@ _cvsid = '$Id$'
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import copy
|
import copy
|
||||||
import xdrlib
|
import struct
|
||||||
import random
|
import random
|
||||||
from types import ListType, StringType
|
from types import ListType, StringType
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
@ -362,10 +362,11 @@ class bsdTableDB :
|
||||||
# Generate a random 64-bit row ID string
|
# Generate a random 64-bit row ID string
|
||||||
# (note: this code has <64 bits of randomness
|
# (note: this code has <64 bits of randomness
|
||||||
# but it's plenty for our database id needs!)
|
# but it's plenty for our database id needs!)
|
||||||
p = xdrlib.Packer()
|
# We must ensure that no null bytes are in the id value.
|
||||||
p.pack_int(int(random.random()*2147483647))
|
blist = []
|
||||||
p.pack_int(int(random.random()*2147483647))
|
for x in xrange(_rowid_str_len):
|
||||||
newid = p.get_buffer()
|
blist.append(random.randint(1,255))
|
||||||
|
newid = struct.pack('B'*_rowid_str_len, *blist)
|
||||||
|
|
||||||
# Guarantee uniqueness by adding this key to the database
|
# Guarantee uniqueness by adding this key to the database
|
||||||
try:
|
try:
|
||||||
|
@ -444,7 +445,7 @@ class bsdTableDB :
|
||||||
try:
|
try:
|
||||||
dataitem = self.db.get(
|
dataitem = self.db.get(
|
||||||
_data_key(table, column, rowid),
|
_data_key(table, column, rowid),
|
||||||
txn)
|
txn=txn)
|
||||||
self.db.delete(
|
self.db.delete(
|
||||||
_data_key(table, column, rowid),
|
_data_key(table, column, rowid),
|
||||||
txn)
|
txn)
|
||||||
|
|
|
@ -21,9 +21,10 @@
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
import sys, os, re
|
import sys, os, re
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
try:
|
try:
|
||||||
import cPickle
|
import cPickle as pickle
|
||||||
pickle = cPickle
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
@ -42,12 +43,9 @@ except ImportError:
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class TableDBTestCase(unittest.TestCase):
|
class TableDBTestCase(unittest.TestCase):
|
||||||
db_home = 'db_home'
|
|
||||||
db_name = 'test-table.db'
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
|
homeDir = tempfile.mkdtemp()
|
||||||
self.homeDir = homeDir
|
self.testHomeDir = homeDir
|
||||||
try: os.mkdir(homeDir)
|
try: os.mkdir(homeDir)
|
||||||
except os.error: pass
|
except os.error: pass
|
||||||
self.tdb = dbtables.bsdTableDB(
|
self.tdb = dbtables.bsdTableDB(
|
||||||
|
@ -55,10 +53,7 @@ class TableDBTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.tdb.close()
|
self.tdb.close()
|
||||||
import glob
|
shutil.rmtree(self.testHomeDir)
|
||||||
files = glob.glob(os.path.join(self.homeDir, '*'))
|
|
||||||
for file in files:
|
|
||||||
os.remove(file)
|
|
||||||
|
|
||||||
def test01(self):
|
def test01(self):
|
||||||
tabname = "test01"
|
tabname = "test01"
|
||||||
|
|
|
@ -118,6 +118,10 @@ Extension Modules
|
||||||
- Bug #1233: fix bsddb.dbshelve.DBShelf append method to work as
|
- Bug #1233: fix bsddb.dbshelve.DBShelf append method to work as
|
||||||
intended for RECNO databases.
|
intended for RECNO databases.
|
||||||
|
|
||||||
|
- Fix bsddb.dbtables: Don't randomly corrupt newly inserted rows by
|
||||||
|
picking a rowid string with null bytes in it. Such rows could not
|
||||||
|
later be deleted, modified or individually selected.
|
||||||
|
|
||||||
- Bug #1726026: Correct the field names of WIN32_FIND_DATAA and
|
- Bug #1726026: Correct the field names of WIN32_FIND_DATAA and
|
||||||
WIN32_FIND_DATAW structures in the ctypes.wintypes module.
|
WIN32_FIND_DATAW structures in the ctypes.wintypes module.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue