64-bit bugs in new ovdb

Dan Riley dsr at mail.lns.cornell.edu
Thu Oct 5 18:14:23 UTC 2000


First off, inn-bugs can probably ignore my previous message about
2.3.0; I've since had a look at inn-CURRENT and the inn-workers
archive, and discovered that all the issues I reported had already
been addressed.  My apologies for not checking the archives first.
Since I'm now looking at the CURRENT snapshots (because we want
cancelfeed), I've subscribed to inn-workers.

Now, on to new bugs--the new ovdb fails in mysterious ways on
alpha-dec-osf.  The most obvious symptom is:

news_lnscu7> ovdb_stat -g comp.sys.dec
comp.sys.dec: groupstats: low: 73952, high: 74018, count: 67, flag: y
news_lnscu7> ovdb_stat -c comp.sys.dec
comp.sys.dec:    counted: low: 0, high: 0, count: 0

but readers also fail in random ways.  I believe the problem is not
zeroing the datakey struct when it is allocated on the stack--the
struct datakey is defined as

struct datakey {
    group_id_t groupnum;
    ARTNUM artnum;
};

On the alpha, ARTNUM is unsigned long (64 bits) and group_id_t is
defined by ovdb as u_int32_t.  By the common rules of padding C
structs, the compiler adds an extra 32 bit word of padding after
groupnum to 64-bit align artnum.  Since BerkeleyDB apparently treats
the datakey as a chunk of memory sizeof(datakey), that padding *must*
be zeroed (or at least set to a consistent value).  The enclosed patch
adds the appropriate memsets, and appears to fix the obvious problem:

news_lnscu7> ovdb_stat -g comp.sys.dec
comp.sys.dec: groupstats: low: 73952, high: 74018, count: 67, flag: y
news_lnscu7> ovdb_stat -c comp.sys.dec
comp.sys.dec:    counted: low: 73952, high: 74018, count: 67

There may be other places more zeroing is needed--I have not reviewed
the rest of the code for padding problems.

Version stuff:

OSF1 lnscu7.lns.cornell.edu V4.0 1229 alpha alpha
DEC C V5.9-008, 'cc -std1 -fast -D_POSIX_PII_SOCKET -D_SOCKADDR_LEN'
inn-CURRENT-20001004
BerkeleyDB 3.1.17

--- storage/ovdb/ovdb.c~	Wed Oct  4 21:41:51 2000
+++ storage/ovdb/ovdb.c	Thu Oct  5 13:21:22 2000
@@ -562,6 +562,7 @@
 
     memset(&key, 0, sizeof key);
     memset(&val, 0, sizeof val);
+    memset(&dk, 0, sizeof dk);
     dk.groupnum = gno;
     dk.artnum = 0;
 
@@ -752,6 +753,7 @@
 
     memset(&key, 0, sizeof key);
     memset(&val, 0, sizeof val);
+    memset(&dk, 0, sizeof dk);
 
     db = get_db_bynum(gi->current_db);
     if(db == NULL)
@@ -1422,6 +1424,8 @@
     struct datakey dk;
     int ret;
 
+    memset(&dk, 0, sizeof dk);
+
     if(databuflen == 0) {
 	databuflen = BIG_BUFFER;
 	databuf = NEW(char, databuflen);
@@ -1608,6 +1612,7 @@
     switch(s->state) {
     case 0:
 	flags = DB_SET_RANGE;
+	memset(&dk, 0, sizeof dk);
 	dk.groupnum = s->gid;
 	dk.artnum = htonl(s->firstart);
 	s->state = 1;
@@ -1731,6 +1736,7 @@
 	if(db == NULL)
 	    return FALSE;
 
+	memset(&dk, 0, sizeof dk);
 	dk.groupnum = gi.current_gid;
 	dk.artnum = htonl(artnum);
 
@@ -1826,6 +1832,8 @@
     memset(&key, 0, sizeof key);
     memset(&nkey, 0, sizeof nkey);
     memset(&val, 0, sizeof val);
+    memset(&dk, 0, sizeof dk);
+    memset(&ndk, 0, sizeof ndk);
 
     TXN_START(t_expgroup_1, tid);
 

--
Dan Riley                                         dsr at mail.lns.cornell.edu
Wilson Lab, Cornell University      <URL:http://www.lns.cornell.edu/~dsr/>
    "History teaches us that days like this are best spent in bed"



More information about the inn-bugs mailing list