mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +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 sys
|
||||
import copy
|
||||
import xdrlib
|
||||
import struct
|
||||
import random
|
||||
from types import ListType, StringType
|
||||
import cPickle as pickle
|
||||
|
@ -362,10 +362,11 @@ class bsdTableDB :
|
|||
# Generate a random 64-bit row ID string
|
||||
# (note: this code has <64 bits of randomness
|
||||
# but it's plenty for our database id needs!)
|
||||
p = xdrlib.Packer()
|
||||
p.pack_int(int(random.random()*2147483647))
|
||||
p.pack_int(int(random.random()*2147483647))
|
||||
newid = p.get_buffer()
|
||||
# We must ensure that no null bytes are in the id value.
|
||||
blist = []
|
||||
for x in xrange(_rowid_str_len):
|
||||
blist.append(random.randint(1,255))
|
||||
newid = struct.pack('B'*_rowid_str_len, *blist)
|
||||
|
||||
# Guarantee uniqueness by adding this key to the database
|
||||
try:
|
||||
|
@ -444,7 +445,7 @@ class bsdTableDB :
|
|||
try:
|
||||
dataitem = self.db.get(
|
||||
_data_key(table, column, rowid),
|
||||
txn)
|
||||
txn=txn)
|
||||
self.db.delete(
|
||||
_data_key(table, column, rowid),
|
||||
txn)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue