← Back to team overview

touch-packages team mailing list archive

[Bug 1421223] [NEW] Empty value seems to be missing

 

Public bug reported:

I have dbm database with some empty values.
If the first calls to dbm_fetch() happens to query one of them, the returned data contains the NULL pointer, and cannot be distinguished from a missing entry.

See the Python script below. The first call to f.get('1') return None,
the second returns the empty string.

I can reproduce the problem with PyPy, which uses a completely
implementation of the dbm module. The issue is really in dbm_fetch().

I can reproduce the problem with a db-5.3.28 built from source.
The cause probably lies in the file src/db/db_ret.c: no buffer is ever allocated if the returned size is zero.
I suggest to allocate at least one byte, so that the returned pointer is not NULL.


import sys
if sys.version > '3':
    import dbm.ndbm as dbm
else:
    import dbm as dbm

fname = '/tmp/test.db'

def setup():
    f = dbm.open(fname, 'n')
    f['1'] = ''
    f['2'] = 'something'
    f.close()

def test():
    f = dbm.open(fname, 'r')
    print(repr(f.get('1')))  # first time: None
    print(repr(f.get('2')))
    print(repr(f.get('1')))  # second time: b''
    f.close()

setup()
test()

** Affects: db5.3 (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to db5.3 in Ubuntu.
https://bugs.launchpad.net/bugs/1421223

Title:
  Empty value seems to be missing

Status in db5.3 package in Ubuntu:
  New

Bug description:
  I have dbm database with some empty values.
  If the first calls to dbm_fetch() happens to query one of them, the returned data contains the NULL pointer, and cannot be distinguished from a missing entry.

  See the Python script below. The first call to f.get('1') return None,
  the second returns the empty string.

  I can reproduce the problem with PyPy, which uses a completely
  implementation of the dbm module. The issue is really in dbm_fetch().

  I can reproduce the problem with a db-5.3.28 built from source.
  The cause probably lies in the file src/db/db_ret.c: no buffer is ever allocated if the returned size is zero.
  I suggest to allocate at least one byte, so that the returned pointer is not NULL.


  
  import sys
  if sys.version > '3':
      import dbm.ndbm as dbm
  else:
      import dbm as dbm

  fname = '/tmp/test.db'

  def setup():
      f = dbm.open(fname, 'n')
      f['1'] = ''
      f['2'] = 'something'
      f.close()

  def test():
      f = dbm.open(fname, 'r')
      print(repr(f.get('1')))  # first time: None
      print(repr(f.get('2')))
      print(repr(f.get('1')))  # second time: b''
      f.close()

  setup()
  test()

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/db5.3/+bug/1421223/+subscriptions


Follow ups

References