diff options
-rw-r--r-- | usr.sbin/httpd/src/CHANGES.SSL | 12 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/libssl.module | 2 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/libssl.version | 2 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/mod_ssl.h | 5 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_engine_dh.c | 8 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_engine_init.c | 27 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_engine_io.c | 8 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_engine_kernel.c | 6 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c | 12 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_expr_eval.c | 2 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_scache_dbm.c | 4 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_scache_shmcb.c | 28 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_scache_shmht.c | 4 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_util.c | 14 | ||||
-rw-r--r-- | usr.sbin/httpd/src/modules/ssl/ssl_util_sdbm.c | 15 |
15 files changed, 98 insertions, 51 deletions
diff --git a/usr.sbin/httpd/src/CHANGES.SSL b/usr.sbin/httpd/src/CHANGES.SSL index 2dadf0eead4..f8b32d7fbae 100644 --- a/usr.sbin/httpd/src/CHANGES.SSL +++ b/usr.sbin/httpd/src/CHANGES.SSL @@ -23,6 +23,18 @@ / __/ | (_) | __ |_____(_)___/ ___________________________________________ + Changes with mod_ssl 2.8.7 (01-Feb-2002 to 23-Feb-2002) + + *) Support for the latest OpenSSL 0.9.7 snapshots. + + *) Fixed potential buffer overflow in DBM and SHMHT session + cache if very very large certificate chains are used. + + *) Compliance with POSIX 1003.1-2001 (SUSv3) by replacing obsolete + "head -1" and "tail -1" constructs with sed variants in scripts. + + *) Fixed file descriptor leakage under Win32. + Changes with mod_ssl 2.8.6 (16-Oct-2001 to 01-Feb-2002) *) Upgraded to Apache 1.3.23 diff --git a/usr.sbin/httpd/src/modules/ssl/libssl.module b/usr.sbin/httpd/src/modules/ssl/libssl.module index d69e390090e..5034c9a497b 100644 --- a/usr.sbin/httpd/src/modules/ssl/libssl.module +++ b/usr.sbin/httpd/src/modules/ssl/libssl.module @@ -282,7 +282,7 @@ ConfigStart # determine SSL_BASE # if [ ".$SSL_BASE" = . ]; then - SSL_BASE=`egrep '^SSL_BASE=' $file | tail -1 | awk -F= '{print $2}'` + SSL_BASE=`egrep '^SSL_BASE=' $file | sed -n -e '$p' | awk -F= '{print $2}'` if [ ".$SSL_BASE" = . ]; then if [ -d /usr/local/ssl ]; then SSL_BASE="/usr/local/ssl" diff --git a/usr.sbin/httpd/src/modules/ssl/libssl.version b/usr.sbin/httpd/src/modules/ssl/libssl.version index f11257b4dc7..527c0608cc2 100644 --- a/usr.sbin/httpd/src/modules/ssl/libssl.version +++ b/usr.sbin/httpd/src/modules/ssl/libssl.version @@ -1 +1 @@ -mod_ssl/2.8.4-1.3.20 +mod_ssl/2.8.7-1.3.23 diff --git a/usr.sbin/httpd/src/modules/ssl/mod_ssl.h b/usr.sbin/httpd/src/modules/ssl/mod_ssl.h index 990f0dda082..afc1e0dfbe7 100644 --- a/usr.sbin/httpd/src/modules/ssl/mod_ssl.h +++ b/usr.sbin/httpd/src/modules/ssl/mod_ssl.h @@ -720,7 +720,11 @@ int ssl_callback_SSLVerify_CRL(int, X509_STORE_CTX *, server_rec *); int ssl_callback_NewSessionCacheEntry(SSL *, SSL_SESSION *); SSL_SESSION *ssl_callback_GetSessionCacheEntry(SSL *, unsigned char *, int, int *); void ssl_callback_DelSessionCacheEntry(SSL_CTX *, SSL_SESSION *); +#if SSL_LIBRARY_VERSION >= 0x00907000 +void ssl_callback_LogTracingState(const SSL *, int, int); +#else void ssl_callback_LogTracingState(SSL *, int, int); +#endif /* Session Cache Support */ void ssl_scache_init(server_rec *, pool *); @@ -839,6 +843,7 @@ ssl_algo_t ssl_util_algotypeof(X509 *, EVP_PKEY *); char *ssl_util_algotypestr(ssl_algo_t); char *ssl_util_ptxtsub(pool *, const char *, const char *, char *); void ssl_util_thread_setup(void); +void ssl_util_thread_cleanup(void); /* Vendor extension support */ #if defined(SSL_VENDOR) && defined(SSL_VENDOR_OBJS) diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_engine_dh.c b/usr.sbin/httpd/src/modules/ssl/ssl_engine_dh.c index 84f49e66571..c698a90eaba 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_engine_dh.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_engine_dh.c @@ -103,7 +103,7 @@ static unsigned char dh512_g[] = 0x02, }; -static DH *get_dh512() +static DH *get_dh512(void) { DH *dh; @@ -134,7 +134,7 @@ static unsigned char dh1024_g[] = 0x02, }; -static DH *get_dh1024() +static DH *get_dh1024(void) { DH *dh; @@ -227,10 +227,10 @@ $dhinfo = "\n\/\*\n$dhinfo\*\/\n\n"; # generate C source from DH params my $dhsource = ''; -open(FP, "openssl dh -noout -C -in dh512.pem | indent | expand -8 |") || die; +open(FP, "openssl dh -noout -C -in dh512.pem | indent | expand |") || die; $dhsource .= $_ while (<FP>); close(FP); -open(FP, "openssl dh -noout -C -in dh1024.pem | indent | expand -8 |") || die; +open(FP, "openssl dh -noout -C -in dh1024.pem | indent | expand |") || die; $dhsource .= $_ while (<FP>); close(FP); $dhsource =~ s|(DH\s+\*get_dh)|static $1|sg; diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_engine_init.c b/usr.sbin/httpd/src/modules/ssl/ssl_engine_init.c index d8e12d8db4b..6ef24f6006e 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_engine_init.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_engine_init.c @@ -123,7 +123,7 @@ void ssl_init_Module(server_rec *s, pool *p) SSLSrvConfigRec *sc; server_rec *s2; char *cp; -#ifdef __OpenBSD__ +#ifdef __OpenBSD__ int SSLenabled = 0; #endif @@ -257,11 +257,11 @@ void ssl_init_Module(server_rec *s, pool *p) #ifdef __OpenBSD__ for (s2 = s; s2 != NULL; s2 = s2->next) { sc = mySrvConfig(s2); - /* find out if anyone's actually doing ssl */ + /* find out if anyone's actually doing SSL */ if (sc->bEnabled) SSLenabled = 1; } - if (SSLenabled) /* skip expensive bits if we're not doing ssl */ + if (SSLenabled) /* skip expensive bits if we're not doing SSL */ ssl_init_TmpKeysHandle(SSL_TKP_GEN, s, p); #endif @@ -296,15 +296,14 @@ void ssl_init_Module(server_rec *s, pool *p) /* * allocate the temporary RSA keys and DH params */ -#ifdef __OpenBSD__ - if (SSLenabled) /* skip expensive bits if we're not doing ssl */ +#ifdef __OpenBSD__ + if (SSLenabled) /* skip expensive bits if we're not doing SSL */ #endif ssl_init_TmpKeysHandle(SSL_TKP_ALLOC, s, p); /* * initialize servers */ - ssl_log(s, SSL_LOG_INFO, "Init: Initializing (virtual) servers for SSL"); for (s2 = s; s2 != NULL; s2 = s2->next) { sc = mySrvConfig(s2); @@ -406,13 +405,9 @@ void ssl_init_TmpKeysHandle(int action, server_rec *s, pool *p) /* generate 512 bit RSA key */ ssl_log(s, SSL_LOG_INFO, "Init: Generating temporary RSA private keys (512/1024 bits)"); if ((rsa = RSA_generate_key(512, RSA_F4, NULL, NULL)) == NULL) { - ssl_log(s, SSL_LOG_ERROR, "Init: Failed to generate temporary 512 bit RSA private key"); -#if 0 + ssl_log(s, SSL_LOG_ERROR|SSL_ADD_SSLERR, + "Init: Failed to generate temporary 512 bit RSA private key"); ssl_die(); -#else - ssl_log(s, SSL_LOG_ERROR, "Init: You probably have no RSA support in libcrypto. See ssl(8)"); - return; -#endif } asn1 = (ssl_asn1_t *)ssl_ds_table_push(mc->tTmpKeys, "RSA:512"); asn1->nData = i2d_RSAPrivateKey(rsa, NULL); @@ -422,7 +417,8 @@ void ssl_init_TmpKeysHandle(int action, server_rec *s, pool *p) /* generate 1024 bit RSA key */ if ((rsa = RSA_generate_key(1024, RSA_F4, NULL, NULL)) == NULL) { - ssl_log(s, SSL_LOG_ERROR, "Init: Failed to generate temporary 1024 bit RSA private key"); + ssl_log(s, SSL_LOG_ERROR|SSL_ADD_SSLERR, + "Init: Failed to generate temporary 1024 bit RSA private key"); ssl_die(); } asn1 = (ssl_asn1_t *)ssl_ds_table_push(mc->tTmpKeys, "RSA:1024"); @@ -786,7 +782,8 @@ void ssl_init_ConfigureServer(server_rec *s, pool *p, SSLSrvConfigRec *sc) } if (SSL_X509_getCN(p, sc->pPublicCert[i], &cp)) { if (ap_is_fnmatch(cp) && - !ap_fnmatch(cp, s->server_hostname, FNM_PERIOD|FNM_CASE_BLIND)) { + ap_fnmatch(cp, s->server_hostname, + FNM_PERIOD|FNM_CASE_BLIND) == FNM_NOMATCH) { ssl_log(s, SSL_LOG_WARN, "Init: (%s) %s server certificate wildcard CommonName (CN) `%s' " "does NOT match server name!?", cpVHostID, @@ -1108,6 +1105,8 @@ void ssl_init_ModuleKill(void *data) EVP_cleanup(); #endif + ssl_util_thread_cleanup(); + return; } diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_engine_io.c b/usr.sbin/httpd/src/modules/ssl/ssl_engine_io.c index a313eb4d5a1..5974bc51bf4 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_engine_io.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_engine_io.c @@ -443,10 +443,6 @@ static int ssl_io_hook_writev(BUFF *fb, const struct iovec *iov, int iovcnt) #ifdef WIN32 -/* these two functions are exported from buff.c under WIN32 */ -API_EXPORT(int) sendwithtimeout(int sock, const char *buf, int len, int flags); -API_EXPORT(int) recvwithtimeout(int sock, char *buf, int len, int flags); - /* and the prototypes for our SSL_xxx variants */ static int SSL_sendwithtimeout(BUFF *fb, const char *buf, int len); static int SSL_recvwithtimeout(BUFF *fb, char *buf, int len); @@ -459,7 +455,7 @@ static int ssl_io_hook_recvwithtimeout(BUFF *fb, char *buf, int len) if ((ssl = ap_ctx_get(fb->ctx, "ssl")) != NULL) rc = SSL_recvwithtimeout(fb, buf, len); else - rc = recvwithtimeout(fb->fd, buf, len, 0); + rc = ap_recvwithtimeout(fb->fd, buf, len, 0); return rc; } @@ -471,7 +467,7 @@ static int ssl_io_hook_sendwithtimeout(BUFF *fb, const char *buf, int len) if ((ssl = ap_ctx_get(fb->ctx, "ssl")) != NULL) rc = SSL_sendwithtimeout(fb, buf, len); else - rc = sendwithtimeout(fb->fd, buf, len, 0); + rc = ap_sendwithtimeout(fb->fd, buf, len, 0); return rc; } diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_engine_kernel.c b/usr.sbin/httpd/src/modules/ssl/ssl_engine_kernel.c index ca1b3f0a55c..3d891ffb319 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_engine_kernel.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_engine_kernel.c @@ -1835,7 +1835,11 @@ void ssl_callback_DelSessionCacheEntry( * SSL handshake and does SSL record layer stuff. We use it to * trace OpenSSL's processing in out SSL logfile. */ +#if SSL_LIBRARY_VERSION >= 0x00907000 +void ssl_callback_LogTracingState(const SSL *ssl, int where, int rc) +#else void ssl_callback_LogTracingState(SSL *ssl, int where, int rc) +#endif { conn_rec *c; server_rec *s; @@ -1845,7 +1849,7 @@ void ssl_callback_LogTracingState(SSL *ssl, int where, int rc) /* * find corresponding server */ - if ((c = (conn_rec *)SSL_get_app_data(ssl)) == NULL) + if ((c = (conn_rec *)SSL_get_app_data((SSL *)ssl)) == NULL) return; s = c->server; if ((sc = mySrvConfig(s)) == NULL) diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c b/usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c index afb49b4f5c9..8631c86d743 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c @@ -86,6 +86,7 @@ int ssl_rand_seed(server_rec *s, pool *p, ssl_rsctx_t nCtx, char *prefix) int i, n, l; time_t t; pid_t pid; + int m; mc = myModConfig(); nReq = 0; @@ -151,12 +152,13 @@ int ssl_rand_seed(server_rec *s, pool *p, ssl_rsctx_t nCtx, char *prefix) nDone += 128; /* - * seed in an 1KB extract of the current scoreboard + * seed in extract data from the current scoreboard */ - if (ap_scoreboard_image != NULL) { - n = ssl_rand_choosenum(0, SCOREBOARD_SIZE-1024-1); - RAND_seed((unsigned char *)ap_scoreboard_image+n, 1024); - nDone += 1024; + if (ap_scoreboard_image != NULL && SCOREBOARD_SIZE > 16) { + m = ((SCOREBOARD_SIZE / 2) - 1); + n = ssl_rand_choosenum(0, m); + RAND_seed(((unsigned char *)ap_scoreboard_image)+n, m); + nDone += m; } } } diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_expr_eval.c b/usr.sbin/httpd/src/modules/ssl/ssl_expr_eval.c index d8c5ea5f9e2..dc7e7b63074 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_expr_eval.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_expr_eval.c @@ -239,7 +239,7 @@ static char *ssl_expr_eval_func_file(request_rec *r, char *filename) *buf = NUL; } else { - if ((buf = (char *)ap_palloc(r->pool, sizeof(char) * len+1)) == NULL) { + if ((buf = (char *)ap_palloc(r->pool, sizeof(char) * (len+1))) == NULL) { ssl_expr_error = "Cannot allocate memory"; ap_pfclose(r->pool, fp); return ""; diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_scache_dbm.c b/usr.sbin/httpd/src/modules/ssl/ssl_scache_dbm.c index 323c6129918..669658f84ba 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_scache_dbm.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_scache_dbm.c @@ -143,8 +143,10 @@ BOOL ssl_scache_dbm_store(server_rec *s, UCHAR *id, int idlen, time_t expiry, SS UCHAR *ucp; /* streamline session data */ + if ((nData = i2d_SSL_SESSION(sess, NULL)) > sizeof(ucaData)) + return FALSE; ucp = ucaData; - nData = i2d_SSL_SESSION(sess, &ucp); + i2d_SSL_SESSION(sess, &ucp); /* be careful: do not try to store too much bytes in a DBM file! */ #ifdef SSL_USE_SDBM diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_scache_shmcb.c b/usr.sbin/httpd/src/modules/ssl/ssl_scache_shmcb.c index e588f0a5d11..e037e3d961c 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_scache_shmcb.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_scache_shmcb.c @@ -183,9 +183,9 @@ typedef struct { unsigned int division_offset; unsigned int division_size; unsigned int queue_size; - unsigned char index_num; - unsigned char index_offset; - unsigned char index_size; + unsigned int index_num; + unsigned int index_offset; + unsigned int index_size; unsigned int cache_data_offset; unsigned int cache_data_size; unsigned long num_stores; @@ -209,9 +209,9 @@ typedef struct { unsigned int cache_data_offset; unsigned int cache_data_size; unsigned char division_mask; - unsigned char index_num; - unsigned char index_offset; - unsigned char index_size; + unsigned int index_num; + unsigned int index_offset; + unsigned int index_size; #endif } SHMCBHeader; @@ -456,7 +456,7 @@ void ssl_scache_shmcb_kill(server_rec *s) return; } -BOOL ssl_scache_shmcb_store(server_rec *s, UCHAR * id, int idlen, +BOOL ssl_scache_shmcb_store(server_rec *s, UCHAR *id, int idlen, time_t timeout, SSL_SESSION * pSession) { SSLModConfigRec *mc = myModConfig(); @@ -478,7 +478,7 @@ BOOL ssl_scache_shmcb_store(server_rec *s, UCHAR * id, int idlen, return to_return; } -SSL_SESSION *ssl_scache_shmcb_retrieve(server_rec *s, UCHAR * id, int idlen) +SSL_SESSION *ssl_scache_shmcb_retrieve(server_rec *s, UCHAR *id, int idlen) { SSLModConfigRec *mc = myModConfig(); void *shm_segment; @@ -499,14 +499,16 @@ SSL_SESSION *ssl_scache_shmcb_retrieve(server_rec *s, UCHAR * id, int idlen) return pSession; } -void ssl_scache_shmcb_remove(server_rec *s, UCHAR * id, int idlen) +void ssl_scache_shmcb_remove(server_rec *s, UCHAR *id, int idlen) { SSLModConfigRec *mc = myModConfig(); void *shm_segment; /* We've kludged our pointer into the other cache's member variable. */ shm_segment = (void *) mc->tSessionCacheDataTable; + ssl_mutex_on(s); shmcb_remove_session(s, shm_segment, id, idlen); + ssl_mutex_off(s); } void ssl_scache_shmcb_expire(server_rec *s) @@ -705,7 +707,7 @@ static BOOL shmcb_init_memory( } static BOOL shmcb_store_session( - server_rec *s, void *shm_segment, UCHAR * id, + server_rec *s, void *shm_segment, UCHAR *id, int idlen, SSL_SESSION * pSession, time_t timeout) { @@ -755,7 +757,7 @@ static BOOL shmcb_store_session( static SSL_SESSION *shmcb_retrieve_session( server_rec *s, void *shm_segment, - UCHAR * id, int idlen) + UCHAR *id, int idlen) { SHMCBHeader *header; SHMCBQueue queue; @@ -795,7 +797,7 @@ static SSL_SESSION *shmcb_retrieve_session( static BOOL shmcb_remove_session( server_rec *s, void *shm_segment, - UCHAR * id, int idlen) + UCHAR *id, int idlen) { SHMCBHeader *header; SHMCBQueue queue; @@ -992,7 +994,7 @@ static SHMCBIndex *shmcb_get_index( const SHMCBQueue *queue, unsigned int idx) { /* bounds check */ - if (idx > (unsigned int) queue->header->index_num) + if (idx > queue->header->index_num) return NULL; /* Return a pointer to the index. NB: I am being horribly pendantic diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_scache_shmht.c b/usr.sbin/httpd/src/modules/ssl/ssl_scache_shmht.c index 18e688af2c4..fad41e09ff0 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_scache_shmht.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_scache_shmht.c @@ -175,8 +175,10 @@ BOOL ssl_scache_shmht_store(server_rec *s, UCHAR *id, int idlen, time_t expiry, UCHAR *ucp; /* streamline session data */ + if ((nData = i2d_SSL_SESSION(sess, NULL)) > sizeof(ucaData)) + return FALSE; ucp = ucaData; - nData = i2d_SSL_SESSION(sess, &ucp); + i2d_SSL_SESSION(sess, &ucp); ssl_mutex_on(s); if (table_insert_kd(mc->tSessionCacheDataTable, diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_util.c b/usr.sbin/httpd/src/modules/ssl/ssl_util.c index 2fefbb45037..798303f253a 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_util.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_util.c @@ -258,7 +258,7 @@ int ssl_util_ppopen_child(void *cmd, child_info *pinfo) spawnl(P_NOWAIT, SHELL_PATH, SHELL_PATH, "/c", (char *)cmd, NULL); #else /* Standard Unix */ - execl(SHELL_PATH, SHELL_PATH, "-c", (char *)cmd, (char *)NULL); + execl(SHELL_PATH, SHELL_PATH, "-c", (char *)cmd, NULL); #endif return (child_pid); } @@ -435,3 +435,15 @@ void ssl_util_thread_setup(void) return; } +void ssl_util_thread_cleanup(void) +{ +#ifdef WIN32 + int i; + + CRYPTO_set_locking_callback(NULL); + for (i = 0; i < CRYPTO_NUM_LOCKS; i++) + CloseHandle(lock_cs[i]); +#endif /* WIN32 */ + return; +} + diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_util_sdbm.c b/usr.sbin/httpd/src/modules/ssl/ssl_util_sdbm.c index c728f90c864..be156aedc35 100644 --- a/usr.sbin/httpd/src/modules/ssl/ssl_util_sdbm.c +++ b/usr.sbin/httpd/src/modules/ssl/ssl_util_sdbm.c @@ -499,14 +499,17 @@ register long dbit; { register long c; register long dirb; + int got; c = dbit / BYTESIZ; dirb = c / DBLKSIZ; if (dirb != db->dirbno) { if (lseek(db->dirf, OFF_DIR(dirb), SEEK_SET) < 0 - || read(db->dirf, db->dirbuf, DBLKSIZ) < 0) + || (got = read(db->dirf, db->dirbuf, DBLKSIZ)) < 0) return 0; + if (got == 0) + memset(db->dirbuf, 0, DBLKSIZ); db->dirbno = dirb; debug(("dir read: %d\n", dirb)); @@ -522,14 +525,17 @@ register long dbit; { register long c; register long dirb; + int got; c = dbit / BYTESIZ; dirb = c / DBLKSIZ; if (dirb != db->dirbno) { if (lseek(db->dirf, OFF_DIR(dirb), SEEK_SET) < 0 - || read(db->dirf, db->dirbuf, DBLKSIZ) < 0) + || (got = read(db->dirf, db->dirbuf, DBLKSIZ)) < 0) return 0; + if (got == 0) + memset(db->dirbuf, 0, DBLKSIZ); db->dirbno = dirb; debug(("dir read: %d\n", dirb)); @@ -537,8 +543,13 @@ register long dbit; db->dirbuf[c % DBLKSIZ] |= (1 << dbit % BYTESIZ); +#if 0 if (dbit >= db->maxbno) db->maxbno += DBLKSIZ * BYTESIZ; +#else + if (OFF_DIR((dirb+1))*BYTESIZ > db->maxbno) + db->maxbno = OFF_DIR((dirb+1)) * BYTESIZ; +#endif if (lseek(db->dirf, OFF_DIR(dirb), SEEK_SET) < 0 || write(db->dirf, db->dirbuf, DBLKSIZ) < 0) |