Module Name:    src
Committed By:   joerg
Date:           Thu Sep 27 00:37:43 UTC 2012

Modified Files:
        src/lib/libc/cdb: cdbr.c

Log Message:
Don't refuse the open databases without entries or keys, just protect
the divisions. cdbr_find and cdbr_get already have the appropiate
checks.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/cdb/cdbr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/cdb/cdbr.c
diff -u src/lib/libc/cdb/cdbr.c:1.3 src/lib/libc/cdb/cdbr.c:1.4
--- src/lib/libc/cdb/cdbr.c:1.3	Mon Jun  4 19:06:45 2012
+++ src/lib/libc/cdb/cdbr.c	Thu Sep 27 00:37:43 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdbr.c,v 1.3 2012/06/04 19:06:45 joerg Exp $	*/
+/*	$NetBSD: cdbr.c,v 1.4 2012/09/27 00:37:43 joerg Exp $	*/
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: cdbr.c,v 1.3 2012/06/04 19:06:45 joerg Exp $");
+__RCSID("$NetBSD: cdbr.c,v 1.4 2012/09/27 00:37:43 joerg Exp $");
 
 #include "namespace.h"
 
@@ -152,17 +152,21 @@ cdbr_open(const char *path, int flags)
 	    cdbr->data_base < cdbr->mmap_base ||
 	    cdbr->data_base + cdbr->data_size < cdbr->mmap_base ||
 	    cdbr->data_base + cdbr->data_size >
-	    cdbr->mmap_base + cdbr->mmap_size ||
-	    cdbr->entries == 0 || cdbr->entries_index == 0) {
+	    cdbr->mmap_base + cdbr->mmap_size) {
 		errno = EINVAL;
 		cdbr_close(cdbr);
 		return NULL;
 	}
 
-	fast_divide32_prepare(cdbr->entries, &cdbr->entries_m,
-	    &cdbr->entries_s1, &cdbr->entries_s2);
-	fast_divide32_prepare(cdbr->entries_index, &cdbr->entries_index_m,
-	    &cdbr->entries_index_s1, &cdbr->entries_index_s2);
+	if (cdbr->entries) {
+		fast_divide32_prepare(cdbr->entries, &cdbr->entries_m,
+		    &cdbr->entries_s1, &cdbr->entries_s2);
+	}
+	if (cdbr->entries_index) {
+		fast_divide32_prepare(cdbr->entries_index,
+		    &cdbr->entries_index_m,
+		    &cdbr->entries_index_s1, &cdbr->entries_index_s2);
+	}
 
 	return cdbr;
 }

Reply via email to