summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb/dbtables.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-10-18 17:15:20 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-10-18 17:15:20 (GMT)
commit0dcc3cc94926c76223d41a0b36f4c0792ec47089 (patch)
treea43760cf95e0affb91fb3af33e20d79cddff3d98 /Lib/bsddb/dbtables.py
parent574e1ba814b19aafa93519f953529b35aab9fa12 (diff)
downloadcpython-0dcc3cc94926c76223d41a0b36f4c0792ec47089.zip
cpython-0dcc3cc94926c76223d41a0b36f4c0792ec47089.tar.gz
cpython-0dcc3cc94926c76223d41a0b36f4c0792ec47089.tar.bz2
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.
Diffstat (limited to 'Lib/bsddb/dbtables.py')
-rw-r--r--Lib/bsddb/dbtables.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/bsddb/dbtables.py b/Lib/bsddb/dbtables.py
index 492d5fd..f6c7f02 100644
--- a/Lib/bsddb/dbtables.py
+++ b/Lib/bsddb/dbtables.py
@@ -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)