2008-03-03 Ulrich Drepper <drepper@redhat.com> [BZ #5818] * nscd/connections.c (dbs): Add initializers for .suggested_module. (verify_persistent_db): Remove one unnecessary test and add a new one for bad configuration. * nscd/nscd.h (DEFAULT_SUGGESTED_MODULE): Define. * nscd/nscd_conf.c (nscd_parse_file): Provide default values for .suggested_module and .max_db_size and case config file says the values are zero. * nscd/nscd_helper.c (get_mapping): Fail if hash table module is zero. --- libc/nscd/connections.c 5 Jan 2008 09:08:03 -0000 1.108 +++ libc/nscd/connections.c 4 Mar 2008 01:53:50 -0000 1.109 @@ -108,6 +108,7 @@ struct database_dyn dbs[lastdb] = .propagate = 1, .shared = 0, .max_db_size = DEFAULT_MAX_DB_SIZE, + .suggested_module = DEFAULT_SUGGESTED_MODULE, .filename = "/etc/passwd", .db_filename = _PATH_NSCD_PASSWD_DB, .disabled_iov = &pwd_iov_disabled, @@ -126,6 +127,7 @@ struct database_dyn dbs[lastdb] = .propagate = 1, .shared = 0, .max_db_size = DEFAULT_MAX_DB_SIZE, + .suggested_module = DEFAULT_SUGGESTED_MODULE, .filename = "/etc/group", .db_filename = _PATH_NSCD_GROUP_DB, .disabled_iov = &grp_iov_disabled, @@ -144,6 +146,7 @@ struct database_dyn dbs[lastdb] = .propagate = 0, /* Not used. */ .shared = 0, .max_db_size = DEFAULT_MAX_DB_SIZE, + .suggested_module = DEFAULT_SUGGESTED_MODULE, .filename = "/etc/hosts", .db_filename = _PATH_NSCD_HOSTS_DB, .disabled_iov = &hst_iov_disabled, @@ -314,7 +317,7 @@ verify_persistent_db (void *mem, struct struct database_pers_head head_copy = *head; /* Check that the header that was read matches the head in the database. */ - if (readhead != NULL && memcmp (head, readhead, sizeof (*head)) != 0) + if (memcmp (head, readhead, sizeof (*head)) != 0) return 0; /* First some easy tests: make sure the database header is sane. */ @@ -324,6 +327,7 @@ verify_persistent_db (void *mem, struct This should cover daylight saving time changes. */ || head->timestamp > now + 60 * 60 + 60 || (head->gc_cycle & 1) + || head->module == 0 || (size_t) head->module > INT32_MAX / sizeof (ref_t) || (size_t) head->data_size > INT32_MAX - head->module * sizeof (ref_t) || head->first_free < 0 --- libc/nscd/nscd.h 25 Nov 2007 21:06:58 -0000 1.32 +++ libc/nscd/nscd.h 4 Mar 2008 01:53:25 -0000 1.33 @@ -120,6 +120,9 @@ struct database_dyn /* Number of bytes of data we initially reserve for each hash table bucket. */ #define DEFAULT_DATASIZE_PER_BUCKET 1024 +/* Default module of hash table. */ +#define DEFAULT_SUGGESTED_MODULE 211 + /* Number of seconds between two cache pruning runs if we do not have better information when it is really needed. */ --- libc/nscd/nscd_conf.c 16 Jul 2007 00:54:58 -0000 1.22 +++ libc/nscd/nscd_conf.c 4 Mar 2008 01:53:12 -0000 1.23 @@ -140,7 +140,8 @@ nscd_parse_file (const char *fname, stru { int idx = find_db (arg1); if (idx >= 0) - dbs[idx].suggested_module = atol (arg2); + dbs[idx].suggested_module + = atol (arg2) ?: DEFAULT_SUGGESTED_MODULE; } else if (strcmp (entry, "enable-cache") == 0) { @@ -168,7 +169,7 @@ nscd_parse_file (const char *fname, stru { int idx = find_db (arg1); if (idx >= 0) - dbs[idx].max_db_size = atol (arg2); + dbs[idx].max_db_size = atol (arg2) ?: DEFAULT_MAX_DB_SIZE; } else if (strcmp (entry, "logfile") == 0) set_logfile (arg1); --- libc/nscd/nscd_helper.c 13 Oct 2007 19:03:17 -0000 1.31 +++ libc/nscd/nscd_helper.c 4 Mar 2008 01:52:55 -0000 1.32 @@ -263,6 +263,9 @@ get_mapping (request_type type, const ch if (__builtin_expect (head.version != DB_VERSION, 0) || __builtin_expect (head.header_size != sizeof (head), 0) + /* Catch some misconfiguration. The server should catch + them now but some older versions did not. */ + || __builtin_expect (head.module == 0, 0) /* This really should not happen but who knows, maybe the update thread got stuck. */ || __builtin_expect (! head.nscd_certainly_running