From 0a2b352b03317e999da1f6267e4f52c363714806 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sun, 28 Nov 2021 19:28:43 +0000 Subject: Stop using MAXBSIZE to eliminate sys/param.h including (which injects a ton of namespace intrusion). Create local sizes, and refactor some code along the way. ok millert --- bin/cp/utils.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'bin/cp') diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 5c9c9e1b6c0..347081151f2 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.c,v 1.49 2021/10/24 21:24:21 deraadt Exp $ */ +/* $OpenBSD: utils.c,v 1.50 2021/11/28 19:28:41 deraadt Exp $ */ /* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */ /*- @@ -30,7 +30,7 @@ * SUCH DAMAGE. */ -#include /* MAXBSIZE */ +#include #include #include #include @@ -47,6 +47,8 @@ #include "extern.h" +#define _MAXBSIZE (64 * 1024) + int copy_overwrite(void); int @@ -56,17 +58,18 @@ copy_file(FTSENT *entp, int exists) static char *zeroes; struct stat to_stat, *fs; int from_fd, rcount, rval, to_fd, wcount; + const size_t buflen = _MAXBSIZE; #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED char *p; #endif if (!buf) { - buf = malloc(MAXBSIZE); + buf = malloc(buflen); if (!buf) err(1, "malloc"); } if (!zeroes) { - zeroes = calloc(1, MAXBSIZE); + zeroes = calloc(1, buflen); if (!zeroes) err(1, "calloc"); } @@ -141,7 +144,7 @@ copy_file(FTSENT *entp, int exists) struct stat tosb; if (!fstat(to_fd, &tosb) && S_ISREG(tosb.st_mode)) skipholes = 1; - while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) { + while ((rcount = read(from_fd, buf, buflen)) > 0) { if (skipholes && memcmp(buf, zeroes, rcount) == 0) wcount = lseek(to_fd, rcount, SEEK_CUR) == -1 ? -1 : rcount; else -- cgit v1.2.3