diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2017-05-26 21:23:15 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2017-05-26 21:23:15 +0000 |
commit | 4085b68fed31688f6a889b422d1c606002faa1cf (patch) | |
tree | 6aec8c7e22129d0f7a8df0615a6c33bbc2bcea10 /usr.sbin/ldapd | |
parent | a828a8a319cb12ef8efa71ae19ae932ad89eedd7 (diff) |
Don't overflow uint16 when the filesystem block size is >32K.
Reported and initial diagnosis from Allan Streib, help/ok millert deraadt
Diffstat (limited to 'usr.sbin/ldapd')
-rw-r--r-- | usr.sbin/ldapd/btree.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.sbin/ldapd/btree.c b/usr.sbin/ldapd/btree.c index 9eb3e19011c..4ef88909117 100644 --- a/usr.sbin/ldapd/btree.c +++ b/usr.sbin/ldapd/btree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: btree.c,v 1.37 2016/12/02 05:52:01 jmatthew Exp $ */ +/* $OpenBSD: btree.c,v 1.38 2017/05/26 21:23:14 sthen Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se> @@ -55,6 +55,7 @@ #define P_INVALID 0xFFFFFFFF #define F_ISSET(w, f) (((w) & (f)) == (f)) +#define MINIMUM(a,b) ((a) < (b) ? (a) : (b)) typedef uint32_t pgno_t; typedef uint16_t indx_t; @@ -844,10 +845,11 @@ btree_write_header(struct btree *bt, int fd) DPRINTF("writing header page"); assert(bt != NULL); - /* Ask stat for 'optimal blocksize for I/O'. + /* + * Ask stat for 'optimal blocksize for I/O', but cap to fit in indx_t. */ if (fstat(fd, &sb) == 0) - psize = sb.st_blksize; + psize = MINIMUM(32*1024, sb.st_blksize); else psize = PAGESIZE; |