Subject: sdbm bug!

From: [email-masked] (David A Keldsen)
Date: Wed, 13 Mar 91 23:09 EST

>Xref: sq comp.unix.ultrix:6199 comp.unix.questions:27525 comp.unix.wizards:595 comp.sources.d:6376 comp.databases:8599 comp.os.minix:13941 comp.windows.x:26982 news.software.b:6754 comp.lang.perl:4326 comp.mail.sendmail:2784 comp.sources.bugs:2779
>Path: sq!geac!censor!utzoo!news-server.csri.toronto.edu!helios.physics.utoronto.ca!ists!yunexus!nexus.YorkU.CA!oz
>From: [email-masked] (Ozan Yigit)
>Newsgroups: comp.unix.ultrix,comp.unix.questions,comp.unix.wizards,comp.sources.d,comp.databases,comp.os.minix,comp.windows.x,news.software.b,comp.lang.perl,comp.mail.sendmail,comp.sources.bugs
>Subject: important sdbm (ndbm clone) bugfix
>Message-ID: <[email-masked]>
>Date: 8 Mar 91 07:30:41 GMT
>Sender: [email-masked]
>Organization: York U. Communications Research & Development
>Lines: 50

[sorry to have to crosspost this wide]

The recent public distribution of sdbm, an ndbm clone came with a subtle bug
[parens, damn parens] that seems to have gone unnoticed for a very long
time. I am thankful to Ronald S. H. Khoo ([email-masked]) for
discovering this bug.

The bug will make some data inaccessible altogether. In one case, 135
entries out of a thousand could not be located in the database. The reason
for the bug to remain unnoticed is probably due to the way sdbm [or ndbm]
is often utilized: short keys with short-to-medium variable-length data.
This use along with sdbm's good page splitting behaviour means the buggy
portion of the code that handles multiple split attempts gets used rarely.

A patch for this nasty bug is included.

FTP: ~ftp/pub/oz/sdbm.shar.Z on nexus.yorku.ca [130.63.9.1] is updated.

My sincere apologies for any inconvenience this bug may have caused. 

oz
---

*** sdbm-dist/sdbm.c	Thu Dec 13 13:52:45 1990
--- sdbm-work/sdbm.c	Fri Mar  8 01:29:40 1991
***************
*** 337,345 ****
   * need to read in anything. BUT we have to write the current
   * [deferred] page out, as the window of failure is too great.
   */
! 		db->curbit = 2 * db->curbit + 
! 			(hash & (db->hmask + 1)) ? 2 : 1;
! 		db->hmask |= (db->hmask + 1);
  
  		if (lseek(db->pagf, OFF_PAG(db->pagbno), SEEK_SET) < 0
  		    || write(db->pagf, db->pagbuf, PBLKSIZ) < 0)
--- 337,345 ----
   * need to read in anything. BUT we have to write the current
   * [deferred] page out, as the window of failure is too great.
   */
! 		db->curbit = 2 * db->curbit +
! 			((hash & (db->hmask + 1)) ? 2 : 1);
! 		db->hmask |= db->hmask + 1;
  
  		if (lseek(db->pagf, OFF_PAG(db->pagbno), SEEK_SET) < 0
  		    || write(db->pagf, db->pagbuf, PBLKSIZ) < 0)

---
In seeking the unattainable, simplicity  |  Internet: [email-masked]
only gets in the way. -- Alan J. Perlis  |  Uucp: utai/utzoo!yunexus!oz