summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-10-18 16:32:02 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-10-18 16:32:02 (GMT)
commit3ef21cb7c61236453b257c30ce08f8f58489e802 (patch)
tree996d4cede829eae538832dde4b8db1ae8112b93d /Lib/bsddb
parentf8a2a0b5a9edc5769b2da40c36c49eed4c5c1b33 (diff)
downloadcpython-3ef21cb7c61236453b257c30ce08f8f58489e802.zip
cpython-3ef21cb7c61236453b257c30ce08f8f58489e802.tar.gz
cpython-3ef21cb7c61236453b257c30ce08f8f58489e802.tar.bz2
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
Diffstat (limited to 'Lib/bsddb')
-rw-r--r--Lib/bsddb/dbtables.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/bsddb/dbtables.py b/Lib/bsddb/dbtables.py
index 37a12c8..f793055 100644
--- a/Lib/bsddb/dbtables.py
+++ b/Lib/bsddb/dbtables.py
@@ -360,12 +360,13 @@ class bsdTableDB :
unique = 0
while not unique:
# Generate a random 64-bit row ID string
- # (note: this code has <56 bits of randomness
+ # (note: this code has <64 bits of randomness
# but it's plenty for our database id needs!)
- # The | 0x01010101 is to ensure no null bytes are in the value
- newid = struct.pack('ll',
- random.randint(0, 2147483647) | 0x01010101,
- random.randint(0, 2147483647) | 0x01010101)
+ # 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: