[PATCH] Fix for database locking crashes (was Re: bogofilter/bogoutil concurrency crash?)

Jim Correia jim.correia at pobox.com
Mon Apr 7 05:35:20 CEST 2003


On Monday, April 7, 2003, at 12:16  AM, David Relson wrote:

> Just post the patch to the mailing list.  I'll get it and can test it.

Ok. Here it is. As you'll see since we were peeking at disposed memory 
this can actually fail on any system. (Maybe the malloc allocator on 
Mac OS X makes it more likely by scribbling on the freed block right 
away.)

I'm not completely familiar with the code, but it looks like the right 
fix. It passes all 'make check' tests now, and also fixes the crash 
previously described.

(I don't usually use the CLI to generate diffs/patches - I hope this 
comes out at the other end in tact.)

======================================================================
--- bogofilter-0.11.1.6-orig/src/datastore_db.c	Fri Mar 28 10:15:58 2003
+++ bogofilter-0.11.1.6/src/datastore_db.c	Sun Apr  6 23:26:00 2003
@@ -183,6 +183,7 @@
  	    handle->dbp->err (handle->dbp, ret, "%s (db) get_byteswapped: %s",
  		    progname, db_file);
  	    db_close(handle, false);
+	    handle = NULL;	/* db_close freed it, we don't want to use it 
anymore */
  	    goto open_err;
  	}

@@ -191,6 +192,7 @@
  	    handle->dbp->err (handle->dbp, ret, "%s (db) fd: %s",
  		    progname, db_file);
  	    db_close(handle, false);
+	    handle = NULL;	/* db_close freed it, we don't want to use it 
anymore */
  	    goto open_err;
  	}

@@ -200,16 +202,19 @@
  	    int e = errno;
  	    handle->fd = -1;
  	    db_close(handle, true);
+	    handle = NULL;	/* db_close freed it, we don't want to use it 
anymore */
  	    errno = e;
  	    /* do not bother to retry if the problem wasn't EAGAIN */
  	    if (e != EAGAIN && e != EACCES) return NULL;
-	    /* do not goto open_err here, db_close frees the handle! */
+		/* it is ok to go to open_err here because we also set handle to 
NULL,
+		   and dbh_free is NULL safe as implemented */
+		goto open_err;
  	} else {
  	    break;
  	}
      }

-    if (handle -> fd >= 0) {
+    if (handle && (handle -> fd >= 0)) {
  	handle->locked = true;
  	return (void *)handle;
      }
======================================================================





More information about the bogofilter-dev mailing list