]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream commit
authorderaadt@openbsd.org <deraadt@openbsd.org>
Mon, 12 Sep 2016 01:22:38 +0000 (01:22 +0000)
committerDarren Tucker <dtucker@zip.com.au>
Mon, 12 Sep 2016 03:46:29 +0000 (13:46 +1000)
Add MAXIMUM(), MINIMUM(), and ROUNDUP() to misc.h, then
use those definitions rather than pulling <sys/param.h> and unknown namespace
pollution. ok djm markus dtucker

Upstream-ID: 712cafa816c9f012a61628b66b9fbd5687223fb8

22 files changed:
channels.c
clientloop.c
dh.c
gss-genr.c
kex.c
kexgexc.c
kexgexs.c
krl.c
misc.h
moduli.c
packet.c
sandbox-rlimit.c
scp.c
serverloop.c
sftp-client.c
sftp-common.c
sftp-server.c
sftp.c
ssh-agent.c
sshbuf.c
sshconnect.c
sshkey.c

index 9f9e972f4291982427ec6e70774a519d038bf3ab..241aa3cdc58d18399576e3d33cd10833a4d48028 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.c,v 1.351 2016/07/19 11:38:53 dtucker Exp $ */
+/* $OpenBSD: channels.c,v 1.352 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -42,7 +42,6 @@
 #include "includes.h"
 
 #include <sys/types.h>
-#include <sys/param.h> /* MIN MAX */
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/un.h>
@@ -245,9 +244,9 @@ channel_register_fds(Channel *c, int rfd, int wfd, int efd,
     int extusage, int nonblock, int is_tty)
 {
        /* Update the maximum file descriptor value. */
-       channel_max_fd = MAX(channel_max_fd, rfd);
-       channel_max_fd = MAX(channel_max_fd, wfd);
-       channel_max_fd = MAX(channel_max_fd, efd);
+       channel_max_fd = MAXIMUM(channel_max_fd, rfd);
+       channel_max_fd = MAXIMUM(channel_max_fd, wfd);
+       channel_max_fd = MAXIMUM(channel_max_fd, efd);
 
        if (rfd != -1)
                fcntl(rfd, F_SETFD, FD_CLOEXEC);
@@ -373,9 +372,9 @@ channel_find_maxfd(void)
        for (i = 0; i < channels_alloc; i++) {
                c = channels[i];
                if (c != NULL) {
-                       max = MAX(max, c->rfd);
-                       max = MAX(max, c->wfd);
-                       max = MAX(max, c->efd);
+                       max = MAXIMUM(max, c->rfd);
+                       max = MAXIMUM(max, c->wfd);
+                       max = MAXIMUM(max, c->efd);
                }
        }
        return max;
@@ -1898,7 +1897,7 @@ read_mux(Channel *c, u_int need)
 
        if (buffer_len(&c->input) < need) {
                rlen = need - buffer_len(&c->input);
-               len = read(c->rfd, buf, MIN(rlen, CHAN_RBUF));
+               len = read(c->rfd, buf, MINIMUM(rlen, CHAN_RBUF));
                if (len < 0 && (errno == EINTR || errno == EAGAIN))
                        return buffer_len(&c->input);
                if (len <= 0) {
@@ -2201,7 +2200,7 @@ channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
 {
        u_int n, sz, nfdset;
 
-       n = MAX(*maxfdp, channel_max_fd);
+       n = MAXIMUM(*maxfdp, channel_max_fd);
 
        nfdset = howmany(n+1, NFDBITS);
        /* Explicitly test here, because xrealloc isn't always called */
@@ -3633,7 +3632,7 @@ connect_next(struct channel_connect *cctx)
 {
        int sock, saved_errno;
        struct sockaddr_un *sunaddr;
-       char ntop[NI_MAXHOST], strport[MAX(NI_MAXSERV,sizeof(sunaddr->sun_path))];
+       char ntop[NI_MAXHOST], strport[MAXIMUM(NI_MAXSERV,sizeof(sunaddr->sun_path))];
 
        for (; cctx->ai; cctx->ai = cctx->ai->ai_next) {
                switch (cctx->ai->ai_family) {
index 2c44f5d19d55fc434b6cf46e2d1857acffcc101a..47098f3af94be0d5f3fe716bb6b8e4b0361c21c6 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.286 2016/07/23 02:54:08 djm Exp $ */
+/* $OpenBSD: clientloop.c,v 1.287 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -61,7 +61,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN MAX */
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #ifdef HAVE_SYS_STAT_H
@@ -672,16 +671,16 @@ client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp,
                server_alive_time = now + options.server_alive_interval;
        }
        if (options.rekey_interval > 0 && compat20 && !rekeying)
-               timeout_secs = MIN(timeout_secs, packet_get_rekey_timeout());
+               timeout_secs = MINIMUM(timeout_secs, packet_get_rekey_timeout());
        set_control_persist_exit_time();
        if (control_persist_exit_time > 0) {
-               timeout_secs = MIN(timeout_secs,
+               timeout_secs = MINIMUM(timeout_secs,
                        control_persist_exit_time - now);
                if (timeout_secs < 0)
                        timeout_secs = 0;
        }
        if (minwait_secs != 0)
-               timeout_secs = MIN(timeout_secs, (int)minwait_secs);
+               timeout_secs = MINIMUM(timeout_secs, (int)minwait_secs);
        if (timeout_secs == INT_MAX)
                tvp = NULL;
        else {
@@ -1553,7 +1552,7 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
        buffer_high = 64 * 1024;
        connection_in = packet_get_connection_in();
        connection_out = packet_get_connection_out();
-       max_fd = MAX(connection_in, connection_out);
+       max_fd = MAXIMUM(connection_in, connection_out);
 
        if (!compat20) {
                /* enable nonblocking unless tty */
@@ -1563,9 +1562,9 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
                        set_nonblock(fileno(stdout));
                if (!isatty(fileno(stderr)))
                        set_nonblock(fileno(stderr));
-               max_fd = MAX(max_fd, fileno(stdin));
-               max_fd = MAX(max_fd, fileno(stdout));
-               max_fd = MAX(max_fd, fileno(stderr));
+               max_fd = MAXIMUM(max_fd, fileno(stdin));
+               max_fd = MAXIMUM(max_fd, fileno(stdout));
+               max_fd = MAXIMUM(max_fd, fileno(stderr));
        }
        quit_pending = 0;
        escape_char1 = escape_char_arg;
diff --git a/dh.c b/dh.c
index 167d3714ed3122e158c382aa77d519f817a692d3..194f29b155941eeb31fb9c08eb398882d0163cb3 100644 (file)
--- a/dh.c
+++ b/dh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dh.c,v 1.60 2016/05/02 10:26:04 djm Exp $ */
+/* $OpenBSD: dh.c,v 1.61 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2000 Niels Provos.  All rights reserved.
  *
@@ -25,7 +25,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN */
 
 #include <openssl/bn.h>
 #include <openssl/dh.h>
@@ -272,7 +271,7 @@ dh_gen_key(DH *dh, int need)
         * Pollard Rho, Big step/Little Step attacks are O(sqrt(n)),
         * so double requested need here.
         */
-       dh->length = MIN(need * 2, pbits - 1);
+       dh->length = MINIMUM(need * 2, pbits - 1);
        if (DH_generate_key(dh) == 0 ||
            !dh_pub_is_valid(dh, dh->pub_key)) {
                BN_clear_free(dh->priv_key);
index d617d600a5dc18356f7ea93691197637feb31c39..62559ed9ec444212b298f4a1974fe244a78b5500 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: gss-genr.c,v 1.23 2015/01/20 23:14:00 deraadt Exp $ */
+/* $OpenBSD: gss-genr.c,v 1.24 2016/09/12 01:22:38 deraadt Exp $ */
 
 /*
  * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
@@ -29,7 +29,6 @@
 #ifdef GSSAPI
 
 #include <sys/types.h>
-#include <sys/param.h>
 
 #include <limits.h>
 #include <stdarg.h>
diff --git a/kex.c b/kex.c
index 1e3bdad5541e76746dd71a4ea47761fc2fb38818..3f08720e381d4b86ac65dcb7640570e75ad0bbbc 100644 (file)
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kex.c,v 1.119 2016/09/06 09:14:05 markus Exp $ */
+/* $OpenBSD: kex.c,v 1.120 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
  *
@@ -25,7 +25,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MAX roundup */
 
 #include <signal.h>
 #include <stdarg.h>
@@ -833,14 +832,14 @@ kex_choose_conf(struct ssh *ssh)
        need = dh_need = 0;
        for (mode = 0; mode < MODE_MAX; mode++) {
                newkeys = kex->newkeys[mode];
-               need = MAX(need, newkeys->enc.key_len);
-               need = MAX(need, newkeys->enc.block_size);
-               need = MAX(need, newkeys->enc.iv_len);
-               need = MAX(need, newkeys->mac.key_len);
-               dh_need = MAX(dh_need, cipher_seclen(newkeys->enc.cipher));
-               dh_need = MAX(dh_need, newkeys->enc.block_size);
-               dh_need = MAX(dh_need, newkeys->enc.iv_len);
-               dh_need = MAX(dh_need, newkeys->mac.key_len);
+               need = MAXIMUM(need, newkeys->enc.key_len);
+               need = MAXIMUM(need, newkeys->enc.block_size);
+               need = MAXIMUM(need, newkeys->enc.iv_len);
+               need = MAXIMUM(need, newkeys->mac.key_len);
+               dh_need = MAXIMUM(dh_need, cipher_seclen(newkeys->enc.cipher));
+               dh_need = MAXIMUM(dh_need, newkeys->enc.block_size);
+               dh_need = MAXIMUM(dh_need, newkeys->enc.iv_len);
+               dh_need = MAXIMUM(dh_need, newkeys->mac.key_len);
        }
        /* XXX need runden? */
        kex->we_need = need;
@@ -871,7 +870,7 @@ derive_key(struct ssh *ssh, int id, u_int need, u_char *hash, u_int hashlen,
 
        if ((mdsz = ssh_digest_bytes(kex->hash_alg)) == 0)
                return SSH_ERR_INVALID_ARGUMENT;
-       if ((digest = calloc(1, roundup(need, mdsz))) == NULL) {
+       if ((digest = calloc(1, ROUNDUP(need, mdsz))) == NULL) {
                r = SSH_ERR_ALLOC_FAIL;
                goto out;
        }
index 71ff13352a4c5eeda299696b91e05b0d6fc16416..ad0d1c8c0ae1414e2cfd91944dad638a3c9e39c5 100644 (file)
--- a/kexgexc.c
+++ b/kexgexc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kexgexc.c,v 1.22 2015/05/26 23:23:40 dtucker Exp $ */
+/* $OpenBSD: kexgexc.c,v 1.23 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2000 Niels Provos.  All rights reserved.
  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
@@ -28,7 +28,6 @@
 
 #ifdef WITH_OPENSSL
 
-#include <sys/param.h>
 #include <sys/types.h>
 
 #include <openssl/dh.h>
@@ -50,6 +49,7 @@
 #include "dispatch.h"
 #include "ssherr.h"
 #include "sshbuf.h"
+#include "misc.h"
 
 static int input_kex_dh_gex_group(int, u_int32_t, void *);
 static int input_kex_dh_gex_reply(int, u_int32_t, void *);
@@ -67,7 +67,7 @@ kexgex_client(struct ssh *ssh)
        kex->max = DH_GRP_MAX;
        kex->nbits = nbits;
        if (datafellows & SSH_BUG_DHGEX_LARGE)
-               kex->nbits = MIN(kex->nbits, 4096);
+               kex->nbits = MINIMUM(kex->nbits, 4096);
        /* New GEX request */
        if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REQUEST)) != 0 ||
            (r = sshpkt_put_u32(ssh, kex->min)) != 0 ||
index f4400dcbe86c87664b68cc784a4eea7be4094c37..449603592cc6de6aec0dafafe297f2f0a86a0a37 100644 (file)
--- a/kexgexs.c
+++ b/kexgexs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kexgexs.c,v 1.29 2016/06/08 02:13:01 dtucker Exp $ */
+/* $OpenBSD: kexgexs.c,v 1.30 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2000 Niels Provos.  All rights reserved.
  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
@@ -28,7 +28,6 @@
 
 #ifdef WITH_OPENSSL
 
-#include <sys/param.h> /* MIN MAX */
 
 #include <stdarg.h>
 #include <stdio.h>
@@ -53,6 +52,7 @@
 #include "dispatch.h"
 #include "ssherr.h"
 #include "sshbuf.h"
+#include "misc.h"
 
 static int input_kex_dh_gex_request(int, u_int32_t, void *);
 static int input_kex_dh_gex_init(int, u_int32_t, void *);
@@ -83,10 +83,10 @@ input_kex_dh_gex_request(int type, u_int32_t seq, void *ctxt)
        kex->nbits = nbits;
        kex->min = min;
        kex->max = max;
-       min = MAX(DH_GRP_MIN, min);
-       max = MIN(DH_GRP_MAX, max);
-       nbits = MAX(DH_GRP_MIN, nbits);
-       nbits = MIN(DH_GRP_MAX, nbits);
+       min = MAXIMUM(DH_GRP_MIN, min);
+       max = MINIMUM(DH_GRP_MAX, max);
+       nbits = MAXIMUM(DH_GRP_MIN, nbits);
+       nbits = MINIMUM(DH_GRP_MAX, nbits);
 
        if (kex->max < kex->min || kex->nbits < kex->min ||
            kex->max < kex->nbits || kex->max < DH_GRP_MIN) {
diff --git a/krl.c b/krl.c
index fff1a3f7cbaf8340c339d17afe3396dad2955d9f..e271a193440769f6cf76d93e7b57e473ff5d267a 100644 (file)
--- a/krl.c
+++ b/krl.c
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $OpenBSD: krl.c,v 1.37 2015/12/31 00:33:52 djm Exp $ */
+/* $OpenBSD: krl.c,v 1.38 2016/09/12 01:22:38 deraadt Exp $ */
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN */
 #include <sys/types.h>
 #include <openbsd-compat/sys-tree.h>
 #include <openbsd-compat/sys-queue.h>
@@ -121,7 +120,7 @@ blob_cmp(struct revoked_blob *a, struct revoked_blob *b)
        int r;
 
        if (a->len != b->len) {
-               if ((r = memcmp(a->blob, b->blob, MIN(a->len, b->len))) != 0)
+               if ((r = memcmp(a->blob, b->blob, MINIMUM(a->len, b->len))) != 0)
                        return r;
                return a->len > b->len ? 1 : -1;
        } else
@@ -458,9 +457,9 @@ choose_next_state(int current_state, u_int64_t contig, int final,
         * Avoid unsigned overflows.
         * The limits are high enough to avoid confusing the calculations.
         */
-       contig = MIN(contig, 1ULL<<31);
-       last_gap = MIN(last_gap, 1ULL<<31);
-       next_gap = MIN(next_gap, 1ULL<<31);
+       contig = MINIMUM(contig, 1ULL<<31);
+       last_gap = MINIMUM(last_gap, 1ULL<<31);
+       next_gap = MINIMUM(next_gap, 1ULL<<31);
 
        /*
         * Calculate the cost to switch from the current state to candidates.
@@ -486,8 +485,8 @@ choose_next_state(int current_state, u_int64_t contig, int final,
        /* Estimate base cost in bits of each section type */
        cost_list += 64 * contig + (final ? 0 : 8+64);
        cost_range += (2 * 64) + (final ? 0 : 8+64);
-       cost_bitmap += last_gap + contig + (final ? 0 : MIN(next_gap, 8+64));
-       cost_bitmap_restart += contig + (final ? 0 : MIN(next_gap, 8+64));
+       cost_bitmap += last_gap + contig + (final ? 0 : MINIMUM(next_gap, 8+64));
+       cost_bitmap_restart += contig + (final ? 0 : MINIMUM(next_gap, 8+64));
 
        /* Convert to byte costs for actual comparison */
        cost_list = (cost_list + 7) / 8;
diff --git a/misc.h b/misc.h
index ef375577cb527275d0127a5c9572fed34aeef131..8f954198bb20b37eaba5af13c4167ebcf7fa8edf 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.58 2016/08/27 04:05:12 guenther Exp $ */
+/* $OpenBSD: misc.h,v 1.59 2016/09/12 01:22:38 deraadt Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -141,4 +141,8 @@ char        *read_passphrase(const char *, int);
 int     ask_permission(const char *, ...) __attribute__((format(printf, 1, 2)));
 int     read_keyfile_line(FILE *, const char *, char *, size_t, u_long *);
 
+#define MINIMUM(a, b)  (((a) < (b)) ? (a) : (b))
+#define MAXIMUM(a, b)  (((a) > (b)) ? (a) : (b))
+#define ROUNDUP(x, y)   ((((x)+((y)-1))/(y))*(y))
+
 #endif /* _MISC_H */
index ed1bdc9467cfc9c5b44a30ae302a1c57d0ac385b..e983b07b74c91ab4e4b94b24b5c38e5306289d7b 100644 (file)
--- a/moduli.c
+++ b/moduli.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: moduli.c,v 1.30 2015/01/20 23:14:00 deraadt Exp $ */
+/* $OpenBSD: moduli.c,v 1.31 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright 1994 Phil Karn <karn@qualcomm.com>
  * Copyright 1996-1998, 2003 William Allen Simpson <wsimpson@greendragon.com>
@@ -41,7 +41,6 @@
 
 #ifdef WITH_OPENSSL
 
-#include <sys/param.h> /* MAX */
 #include <sys/types.h>
 
 #include <openssl/bn.h>
@@ -609,7 +608,7 @@ prime_test(FILE *in, FILE *out, u_int32_t trials, u_int32_t generator_wanted,
 
        if (checkpoint_file != NULL)
                last_processed = read_checkpoint(checkpoint_file);
-       last_processed = start_lineno = MAX(last_processed, start_lineno);
+       last_processed = start_lineno = MAXIMUM(last_processed, start_lineno);
        if (end_lineno == ULONG_MAX)
                debug("process from line %lu from pipe", last_processed);
        else
index 9ee23147ecda9a810ccde5cb5b2f6569b527126f..711091da7f38702b60ebf1bea1085d7e92a7bf16 100644 (file)
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.236 2016/09/06 09:22:56 markus Exp $ */
+/* $OpenBSD: packet.c,v 1.237 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -38,8 +38,7 @@
  */
 
 #include "includes.h"
-#include <sys/param.h> /* MIN roundup */
+
 #include <sys/types.h>
 #include "openbsd-compat/sys-queue.h"
 #include <sys/socket.h>
@@ -1069,7 +1068,7 @@ ssh_set_newkeys(struct ssh *ssh, int mode)
        else
                *max_blocks = ((u_int64_t)1 << 30) / enc->block_size;
        if (state->rekey_limit)
-               *max_blocks = MIN(*max_blocks,
+               *max_blocks = MINIMUM(*max_blocks,
                    state->rekey_limit / enc->block_size);
        debug("rekey after %llu blocks", (unsigned long long)*max_blocks);
        return 0;
@@ -1112,7 +1111,7 @@ ssh_packet_need_rekeying(struct ssh *ssh, u_int outbound_packet_len)
                return 1;
 
        /* Rekey after (cipher-specific) maxiumum blocks */
-       out_blocks = roundup(outbound_packet_len,
+       out_blocks = ROUNDUP(outbound_packet_len,
            state->newkeys[MODE_OUT]->enc.block_size);
        return (state->max_blocks_out &&
            (state->p_send.blocks + out_blocks > state->max_blocks_out)) ||
@@ -1240,7 +1239,7 @@ ssh_packet_send2_wrapped(struct ssh *ssh)
        if (state->extra_pad) {
                tmp = state->extra_pad;
                state->extra_pad =
-                   roundup(state->extra_pad, block_size);
+                   ROUNDUP(state->extra_pad, block_size);
                /* check if roundup overflowed */
                if (state->extra_pad < tmp)
                        return SSH_ERR_INVALID_ARGUMENT;
index bba80778b1a16d10eeeb453d4b2f3ea7d12323f3..0bff3dfba496bc78a9671705b66a6e64af716717 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sandbox-rlimit.c,v 1.3 2011/06/23 09:34:13 djm Exp $ */
+/* $OpenBSD: sandbox-rlimit.c,v 1.4 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
  *
@@ -20,7 +20,6 @@
 #ifdef SANDBOX_RLIMIT
 
 #include <sys/types.h>
-#include <sys/param.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 
diff --git a/scp.c b/scp.c
index 43ca3fa09cd2734e4f70416b1be025e55d5b53a2..c67cd71dfc3aa4760f3dc4d64197d83bfbd16d7e 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scp.c,v 1.186 2016/05/25 23:48:45 schwarze Exp $ */
+/* $OpenBSD: scp.c,v 1.187 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * scp - secure remote copy.  This is basically patched BSD rcp which
  * uses ssh to do the data transfer (instead of using rcmd).
@@ -74,7 +74,6 @@
 #include "includes.h"
 
 #include <sys/types.h>
-#include <sys/param.h>
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
@@ -383,7 +382,7 @@ main(int argc, char **argv)
        setlocale(LC_CTYPE, "");
 
        /* Copy argv, because we modify it */
-       newargv = xcalloc(MAX(argc + 1, 1), sizeof(*newargv));
+       newargv = xcalloc(MAXIMUM(argc + 1, 1), sizeof(*newargv));
        for (n = 0; n < argc; n++)
                newargv[n] = xstrdup(argv[n]);
        argv = newargv;
@@ -1343,7 +1342,7 @@ allocbuf(BUF *bp, int fd, int blksize)
                run_err("fstat: %s", strerror(errno));
                return (0);
        }
-       size = roundup(stb.st_blksize, blksize);
+       size = ROUNDUP(stb.st_blksize, blksize);
        if (size == 0)
                size = blksize;
 #else /* HAVE_STRUCT_STAT_ST_BLKSIZE */
index 1e211701e0a97fbe271aae595cafa8b034149d60..87e619fe44d23ad296a2ece471f49b096648a46b 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: serverloop.c,v 1.185 2016/08/13 17:47:41 markus Exp $ */
+/* $OpenBSD: serverloop.c,v 1.186 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -37,7 +37,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN MAX */
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
@@ -212,7 +211,7 @@ wait_until_can_do_something(int connection_in, int connection_out,
 
        /* XXX need proper deadline system for rekey/client alive */
        if (minwait_secs != 0)
-               max_time_ms = MIN(max_time_ms, (u_int)minwait_secs * 1000);
+               max_time_ms = MINIMUM(max_time_ms, (u_int)minwait_secs * 1000);
 
        /*
         * if using client_alive, set the max timeout accordingly,
@@ -372,8 +371,8 @@ server_loop2(Authctxt *authctxt)
 
        notify_setup();
 
-       max_fd = MAX(connection_in, connection_out);
-       max_fd = MAX(max_fd, notify_pipe[0]);
+       max_fd = MAXIMUM(connection_in, connection_out);
+       max_fd = MAXIMUM(max_fd, notify_pipe[0]);
 
        server_init_dispatch();
 
index 0ca44a4d6d0c43d10484b727dcbbd0acd197356f..e65c15c8f728f9b28f055cbbbc9a3e1d47d456c6 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-client.c,v 1.124 2016/05/25 23:48:45 schwarze Exp $ */
+/* $OpenBSD: sftp-client.c,v 1.125 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
@@ -22,7 +22,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN MAX */
 #include <sys/types.h>
 #ifdef HAVE_SYS_STATVFS_H
 #include <sys/statvfs.h>
@@ -462,7 +461,7 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests,
 
        /* Some filexfer v.0 servers don't support large packets */
        if (ret->version == 0)
-               ret->transfer_buflen = MIN(ret->transfer_buflen, 20480);
+               ret->transfer_buflen = MINIMUM(ret->transfer_buflen, 20480);
 
        ret->limit_kbps = limit_kbps;
        if (ret->limit_kbps > 0) {
@@ -1351,7 +1350,7 @@ do_download(struct sftp_conn *conn, const char *remote_path,
                                    req->offset, req->len, handle, handle_len);
                                /* Reduce the request size */
                                if (len < buflen)
-                                       buflen = MAX(MIN_READ_SIZE, len);
+                                       buflen = MAXIMUM(MIN_READ_SIZE, len);
                        }
                        if (max_req > 0) { /* max_req = 0 iff EOF received */
                                if (size > 0 && offset > size) {
index 9dc1f9831772147e327c464befef06cdeacb1fd4..3a70c52dd3ddaa709d0221dd8ee749721c4abade 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-common.c,v 1.28 2015/01/20 23:14:00 deraadt Exp $ */
+/* $OpenBSD: sftp-common.c,v 1.29 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
  * Copyright (c) 2001 Damien Miller.  All rights reserved.
@@ -26,7 +26,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MAX */
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -45,6 +44,7 @@
 #include "ssherr.h"
 #include "sshbuf.h"
 #include "log.h"
+#include "misc.h"
 
 #include "sftp.h"
 #include "sftp-common.h"
@@ -243,8 +243,8 @@ ls_file(const char *name, const struct stat *st, int remote, int si_units)
        }
        if (sz == 0)
                tbuf[0] = '\0';
-       ulen = MAX(strlen(user), 8);
-       glen = MAX(strlen(group), 8);
+       ulen = MAXIMUM(strlen(user), 8);
+       glen = MAXIMUM(strlen(group), 8);
        if (si_units) {
                fmt_scaled((long long)st->st_size, sbuf);
                snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8s %s %s", mode,
index 646286a3cda577cf4da7e07fce0b45c5136809d8..3619cdfc0ffec232f21d723c7428fe6ef8ab1176 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-server.c,v 1.109 2016/02/15 09:47:49 dtucker Exp $ */
+/* $OpenBSD: sftp-server.c,v 1.110 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2000-2004 Markus Friedl.  All rights reserved.
  *
@@ -17,7 +17,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN */
 #include <sys/types.h>
 #include <sys/stat.h>
 #ifdef HAVE_SYS_TIME_H
@@ -505,7 +504,7 @@ status_to_message(u_int32_t status)
                "Operation unsupported",        /* SSH_FX_OP_UNSUPPORTED */
                "Unknown error"                 /* Others */
        };
-       return (status_messages[MIN(status,SSH2_FX_MAX)]);
+       return (status_messages[MINIMUM(status,SSH2_FX_MAX)]);
 }
 
 static void
diff --git a/sftp.c b/sftp.c
index 08e13a7336a67d7f151cae0ca78168c2cd8045e4..1b5c924983459621c1df4538428bad7e6bfe8eb4 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.175 2016/07/22 03:47:36 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.176 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
@@ -17,7 +17,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN MAX */
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #ifdef HAVE_SYS_STAT_H
@@ -802,7 +801,7 @@ do_ls_dir(struct sftp_conn *conn, const char *path,
                /* Count entries for sort and find longest filename */
                for (n = 0; d[n] != NULL; n++) {
                        if (d[n]->filename[0] != '.' || (lflag & LS_SHOW_ALL))
-                               m = MAX(m, strlen(d[n]->filename));
+                               m = MAXIMUM(m, strlen(d[n]->filename));
                }
 
                /* Add any subpath that also needs to be counted */
@@ -814,9 +813,9 @@ do_ls_dir(struct sftp_conn *conn, const char *path,
                        width = ws.ws_col;
 
                columns = width / (m + 2);
-               columns = MAX(columns, 1);
+               columns = MAXIMUM(columns, 1);
                colspace = width / columns;
-               colspace = MIN(colspace, width);
+               colspace = MINIMUM(colspace, width);
        }
 
        if (lflag & SORT_FLAGS) {
@@ -915,10 +914,10 @@ do_globbed_ls(struct sftp_conn *conn, const char *path,
        if (!(lflag & LS_SHORT_VIEW)) {
                /* Count entries for sort and find longest filename */
                for (i = 0; g.gl_pathv[i]; i++)
-                       m = MAX(m, strlen(g.gl_pathv[i]));
+                       m = MAXIMUM(m, strlen(g.gl_pathv[i]));
 
                columns = width / (m + 2);
-               columns = MAX(columns, 1);
+               columns = MAXIMUM(columns, 1);
                colspace = width / columns;
        }
 
@@ -1669,16 +1668,16 @@ complete_display(char **list, u_int len)
 
        /* Count entries for sort and find longest */
        for (y = 0; list[y]; y++)
-               m = MAX(m, strlen(list[y]));
+               m = MAXIMUM(m, strlen(list[y]));
 
        if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
                width = ws.ws_col;
 
        m = m > len ? m - len : 0;
        columns = width / (m + 2);
-       columns = MAX(columns, 1);
+       columns = MAXIMUM(columns, 1);
        colspace = width / columns;
-       colspace = MIN(colspace, width);
+       colspace = MINIMUM(colspace, width);
 
        printf("\n");
        m = 1;
index 25d6ebc53c942992f191bfd1ba1e40417b2bb24e..fd5f2b35d825fbed88c8ace821b1f574c6e715f3 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-agent.c,v 1.213 2016/05/02 08:49:03 djm Exp $ */
+/* $OpenBSD: ssh-agent.c,v 1.214 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -36,7 +36,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN MAX */
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/resource.h>
@@ -539,7 +538,7 @@ reaper(void)
                                tab->nentries--;
                        } else
                                deadline = (deadline == 0) ? id->death :
-                                   MIN(deadline, id->death);
+                                   MINIMUM(deadline, id->death);
                }
        }
        if (deadline == 0 || deadline <= now)
@@ -991,7 +990,7 @@ prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, u_int *nallocp,
                switch (sockets[i].type) {
                case AUTH_SOCKET:
                case AUTH_CONNECTION:
-                       n = MAX(n, sockets[i].fd);
+                       n = MAXIMUM(n, sockets[i].fd);
                        break;
                case AUTH_UNUSED:
                        break;
@@ -1030,7 +1029,7 @@ prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, u_int *nallocp,
        deadline = reaper();
        if (parent_alive_interval != 0)
                deadline = (deadline == 0) ? parent_alive_interval :
-                   MIN(deadline, parent_alive_interval);
+                   MINIMUM(deadline, parent_alive_interval);
        if (deadline == 0) {
                *tvpp = NULL;
        } else {
index 4d6e0ea0acb0242cf83968ccf1d921f9b1c43c65..91cbd067c56e7d9daee859a67957c5b619247e06 100644 (file)
--- a/sshbuf.c
+++ b/sshbuf.c
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sshbuf.c,v 1.6 2016/01/12 23:42:54 djm Exp $  */
+/*     $OpenBSD: sshbuf.c,v 1.7 2016/09/12 01:22:38 deraadt Exp $      */
 /*
  * Copyright (c) 2011 Damien Miller
  *
@@ -18,7 +18,6 @@
 #define SSHBUF_INTERNAL
 #include "includes.h"
 
-#include <sys/param.h> /* roundup */
 #include <sys/types.h>
 #include <signal.h>
 #include <stdlib.h>
@@ -27,6 +26,7 @@
 
 #include "ssherr.h"
 #include "sshbuf.h"
+#include "misc.h"
 
 static inline int
 sshbuf_check_sanity(const struct sshbuf *buf)
@@ -250,7 +250,7 @@ sshbuf_set_max_size(struct sshbuf *buf, size_t max_size)
                if (buf->size < SSHBUF_SIZE_INIT)
                        rlen = SSHBUF_SIZE_INIT;
                else
-                       rlen = roundup(buf->size, SSHBUF_SIZE_INC);
+                       rlen = ROUNDUP(buf->size, SSHBUF_SIZE_INC);
                if (rlen > max_size)
                        rlen = max_size;
                explicit_bzero(buf->d + buf->size, buf->alloc - buf->size);
@@ -340,7 +340,7 @@ sshbuf_reserve(struct sshbuf *buf, size_t len, u_char **dpp)
                 * allocate less if doing so would overflow max_size.
                 */
                need = len + buf->size - buf->alloc;
-               rlen = roundup(buf->alloc + need, SSHBUF_SIZE_INC);
+               rlen = ROUNDUP(buf->alloc + need, SSHBUF_SIZE_INC);
                SSHBUF_DBG(("need %zu initial rlen %zu", need, rlen));
                if (rlen > buf->max_size)
                        rlen = buf->alloc + need;
index 356ec79f0a0e8aeac499303b8f2e1814ec219a6f..96b91ce1ab4b8a6555de8476f0a70701da125c6f 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshconnect.c,v 1.271 2016/01/14 22:56:56 markus Exp $ */
+/* $OpenBSD: sshconnect.c,v 1.272 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -15,7 +15,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* roundup */
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
@@ -1403,7 +1402,7 @@ ssh_put_password(char *password)
                packet_put_cstring(password);
                return;
        }
-       size = roundup(strlen(password) + 1, 32);
+       size = ROUNDUP(strlen(password) + 1, 32);
        padded = xcalloc(1, size);
        strlcpy(padded, password, size);
        packet_put_string(padded, size);
index 166ac714d6dd835fc2ae3ba552b5f6438dd134ff..8f6173e276dedaa4cd967417baf2e79fd6892420 100644 (file)
--- a/sshkey.c
+++ b/sshkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshkey.c,v 1.36 2016/08/03 05:41:57 djm Exp $ */
+/* $OpenBSD: sshkey.c,v 1.37 2016/09/12 01:22:38 deraadt Exp $ */
 /*
  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
  * Copyright (c) 2008 Alexander von Gernler.  All rights reserved.
@@ -27,7 +27,6 @@
 
 #include "includes.h"
 
-#include <sys/param.h> /* MIN MAX */
 #include <sys/types.h>
 #include <netinet/in.h>
 
@@ -1082,10 +1081,10 @@ fingerprint_randomart(const char *alg, u_char *dgst_raw, size_t dgst_raw_len,
                        y += (input & 0x2) ? 1 : -1;
 
                        /* assure we are still in bounds */
-                       x = MAX(x, 0);
-                       y = MAX(y, 0);
-                       x = MIN(x, FLDSIZE_X - 1);
-                       y = MIN(y, FLDSIZE_Y - 1);
+                       x = MAXIMUM(x, 0);
+                       y = MAXIMUM(y, 0);
+                       x = MINIMUM(x, FLDSIZE_X - 1);
+                       y = MINIMUM(y, FLDSIZE_Y - 1);
 
                        /* augment the field */
                        if (field[x][y] < len - 2)
@@ -1126,7 +1125,7 @@ fingerprint_randomart(const char *alg, u_char *dgst_raw, size_t dgst_raw_len,
        for (y = 0; y < FLDSIZE_Y; y++) {
                *p++ = '|';
                for (x = 0; x < FLDSIZE_X; x++)
-                       *p++ = augmentation_string[MIN(field[x][y], len)];
+                       *p++ = augmentation_string[MINIMUM(field[x][y], len)];
                *p++ = '|';
                *p++ = '\n';
        }