diff options
author | 2017-05-26 21:23:14 +0000 | |
---|---|---|
committer | 2017-05-26 21:23:14 +0000 | |
commit | 3572a0e3e1c276ea1b41c793a2022ebaa1ca992e (patch) | |
tree | e8c071c731598b983e9ebe5ef3ddbbf993c4ccc8 | |
parent | AS 0 is special and should be considered an error. (diff) | |
download | wireguard-openbsd-3572a0e3e1c276ea1b41c793a2022ebaa1ca992e.tar.xz wireguard-openbsd-3572a0e3e1c276ea1b41c793a2022ebaa1ca992e.zip |
Don't overflow uint16 when the filesystem block size is >32K.
Reported and initial diagnosis from Allan Streib, help/ok millert deraadt
-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; |