summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorderaadt@openbsd.org <deraadt@openbsd.org>2016-09-12 01:22:38 +0000
committerDarren Tucker <dtucker@zip.com.au>2016-09-12 13:46:29 +1000
commit9136ec134c97a8aff2917760c03134f52945ff3c (patch)
treebfcab357e6e0f510d9b63bac43b18097e89fa58a
parentf219fc8f03caca7ac82a38ed74bbd6432a1195e7 (diff)
upstream commit
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
-rw-r--r--channels.c21
-rw-r--r--clientloop.c17
-rw-r--r--dh.c5
-rw-r--r--gss-genr.c3
-rw-r--r--kex.c21
-rw-r--r--kexgexc.c6
-rw-r--r--kexgexs.c12
-rw-r--r--krl.c15
-rw-r--r--misc.h6
-rw-r--r--moduli.c5
-rw-r--r--packet.c11
-rw-r--r--sandbox-rlimit.c3
-rw-r--r--scp.c7
-rw-r--r--serverloop.c9
-rw-r--r--sftp-client.c7
-rw-r--r--sftp-common.c8
-rw-r--r--sftp-server.c5
-rw-r--r--sftp.c19
-rw-r--r--ssh-agent.c9
-rw-r--r--sshbuf.c8
-rw-r--r--sshconnect.c5
-rw-r--r--sshkey.c13
22 files changed, 101 insertions, 114 deletions
diff --git a/channels.c b/channels.c
index 9f9e972f4..241aa3cdc 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.351 2016/07/19 11:38:53 dtucker Exp $ */ 1/* $OpenBSD: channels.c,v 1.352 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -42,7 +42,6 @@
42#include "includes.h" 42#include "includes.h"
43 43
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/param.h> /* MIN MAX */
46#include <sys/stat.h> 45#include <sys/stat.h>
47#include <sys/ioctl.h> 46#include <sys/ioctl.h>
48#include <sys/un.h> 47#include <sys/un.h>
@@ -245,9 +244,9 @@ channel_register_fds(Channel *c, int rfd, int wfd, int efd,
245 int extusage, int nonblock, int is_tty) 244 int extusage, int nonblock, int is_tty)
246{ 245{
247 /* Update the maximum file descriptor value. */ 246 /* Update the maximum file descriptor value. */
248 channel_max_fd = MAX(channel_max_fd, rfd); 247 channel_max_fd = MAXIMUM(channel_max_fd, rfd);
249 channel_max_fd = MAX(channel_max_fd, wfd); 248 channel_max_fd = MAXIMUM(channel_max_fd, wfd);
250 channel_max_fd = MAX(channel_max_fd, efd); 249 channel_max_fd = MAXIMUM(channel_max_fd, efd);
251 250
252 if (rfd != -1) 251 if (rfd != -1)
253 fcntl(rfd, F_SETFD, FD_CLOEXEC); 252 fcntl(rfd, F_SETFD, FD_CLOEXEC);
@@ -373,9 +372,9 @@ channel_find_maxfd(void)
373 for (i = 0; i < channels_alloc; i++) { 372 for (i = 0; i < channels_alloc; i++) {
374 c = channels[i]; 373 c = channels[i];
375 if (c != NULL) { 374 if (c != NULL) {
376 max = MAX(max, c->rfd); 375 max = MAXIMUM(max, c->rfd);
377 max = MAX(max, c->wfd); 376 max = MAXIMUM(max, c->wfd);
378 max = MAX(max, c->efd); 377 max = MAXIMUM(max, c->efd);
379 } 378 }
380 } 379 }
381 return max; 380 return max;
@@ -1898,7 +1897,7 @@ read_mux(Channel *c, u_int need)
1898 1897
1899 if (buffer_len(&c->input) < need) { 1898 if (buffer_len(&c->input) < need) {
1900 rlen = need - buffer_len(&c->input); 1899 rlen = need - buffer_len(&c->input);
1901 len = read(c->rfd, buf, MIN(rlen, CHAN_RBUF)); 1900 len = read(c->rfd, buf, MINIMUM(rlen, CHAN_RBUF));
1902 if (len < 0 && (errno == EINTR || errno == EAGAIN)) 1901 if (len < 0 && (errno == EINTR || errno == EAGAIN))
1903 return buffer_len(&c->input); 1902 return buffer_len(&c->input);
1904 if (len <= 0) { 1903 if (len <= 0) {
@@ -2201,7 +2200,7 @@ channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
2201{ 2200{
2202 u_int n, sz, nfdset; 2201 u_int n, sz, nfdset;
2203 2202
2204 n = MAX(*maxfdp, channel_max_fd); 2203 n = MAXIMUM(*maxfdp, channel_max_fd);
2205 2204
2206 nfdset = howmany(n+1, NFDBITS); 2205 nfdset = howmany(n+1, NFDBITS);
2207 /* Explicitly test here, because xrealloc isn't always called */ 2206 /* Explicitly test here, because xrealloc isn't always called */
@@ -3633,7 +3632,7 @@ connect_next(struct channel_connect *cctx)
3633{ 3632{
3634 int sock, saved_errno; 3633 int sock, saved_errno;
3635 struct sockaddr_un *sunaddr; 3634 struct sockaddr_un *sunaddr;
3636 char ntop[NI_MAXHOST], strport[MAX(NI_MAXSERV,sizeof(sunaddr->sun_path))]; 3635 char ntop[NI_MAXHOST], strport[MAXIMUM(NI_MAXSERV,sizeof(sunaddr->sun_path))];
3637 3636
3638 for (; cctx->ai; cctx->ai = cctx->ai->ai_next) { 3637 for (; cctx->ai; cctx->ai = cctx->ai->ai_next) {
3639 switch (cctx->ai->ai_family) { 3638 switch (cctx->ai->ai_family) {
diff --git a/clientloop.c b/clientloop.c
index 2c44f5d19..47098f3af 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: clientloop.c,v 1.286 2016/07/23 02:54:08 djm Exp $ */ 1/* $OpenBSD: clientloop.c,v 1.287 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -61,7 +61,6 @@
61 61
62#include "includes.h" 62#include "includes.h"
63 63
64#include <sys/param.h> /* MIN MAX */
65#include <sys/types.h> 64#include <sys/types.h>
66#include <sys/ioctl.h> 65#include <sys/ioctl.h>
67#ifdef HAVE_SYS_STAT_H 66#ifdef HAVE_SYS_STAT_H
@@ -672,16 +671,16 @@ client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp,
672 server_alive_time = now + options.server_alive_interval; 671 server_alive_time = now + options.server_alive_interval;
673 } 672 }
674 if (options.rekey_interval > 0 && compat20 && !rekeying) 673 if (options.rekey_interval > 0 && compat20 && !rekeying)
675 timeout_secs = MIN(timeout_secs, packet_get_rekey_timeout()); 674 timeout_secs = MINIMUM(timeout_secs, packet_get_rekey_timeout());
676 set_control_persist_exit_time(); 675 set_control_persist_exit_time();
677 if (control_persist_exit_time > 0) { 676 if (control_persist_exit_time > 0) {
678 timeout_secs = MIN(timeout_secs, 677 timeout_secs = MINIMUM(timeout_secs,
679 control_persist_exit_time - now); 678 control_persist_exit_time - now);
680 if (timeout_secs < 0) 679 if (timeout_secs < 0)
681 timeout_secs = 0; 680 timeout_secs = 0;
682 } 681 }
683 if (minwait_secs != 0) 682 if (minwait_secs != 0)
684 timeout_secs = MIN(timeout_secs, (int)minwait_secs); 683 timeout_secs = MINIMUM(timeout_secs, (int)minwait_secs);
685 if (timeout_secs == INT_MAX) 684 if (timeout_secs == INT_MAX)
686 tvp = NULL; 685 tvp = NULL;
687 else { 686 else {
@@ -1553,7 +1552,7 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
1553 buffer_high = 64 * 1024; 1552 buffer_high = 64 * 1024;
1554 connection_in = packet_get_connection_in(); 1553 connection_in = packet_get_connection_in();
1555 connection_out = packet_get_connection_out(); 1554 connection_out = packet_get_connection_out();
1556 max_fd = MAX(connection_in, connection_out); 1555 max_fd = MAXIMUM(connection_in, connection_out);
1557 1556
1558 if (!compat20) { 1557 if (!compat20) {
1559 /* enable nonblocking unless tty */ 1558 /* enable nonblocking unless tty */
@@ -1563,9 +1562,9 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
1563 set_nonblock(fileno(stdout)); 1562 set_nonblock(fileno(stdout));
1564 if (!isatty(fileno(stderr))) 1563 if (!isatty(fileno(stderr)))
1565 set_nonblock(fileno(stderr)); 1564 set_nonblock(fileno(stderr));
1566 max_fd = MAX(max_fd, fileno(stdin)); 1565 max_fd = MAXIMUM(max_fd, fileno(stdin));
1567 max_fd = MAX(max_fd, fileno(stdout)); 1566 max_fd = MAXIMUM(max_fd, fileno(stdout));
1568 max_fd = MAX(max_fd, fileno(stderr)); 1567 max_fd = MAXIMUM(max_fd, fileno(stderr));
1569 } 1568 }
1570 quit_pending = 0; 1569 quit_pending = 0;
1571 escape_char1 = escape_char_arg; 1570 escape_char1 = escape_char_arg;
diff --git a/dh.c b/dh.c
index 167d3714e..194f29b15 100644
--- a/dh.c
+++ b/dh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh.c,v 1.60 2016/05/02 10:26:04 djm Exp $ */ 1/* $OpenBSD: dh.c,v 1.61 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * 4 *
@@ -25,7 +25,6 @@
25 25
26#include "includes.h" 26#include "includes.h"
27 27
28#include <sys/param.h> /* MIN */
29 28
30#include <openssl/bn.h> 29#include <openssl/bn.h>
31#include <openssl/dh.h> 30#include <openssl/dh.h>
@@ -272,7 +271,7 @@ dh_gen_key(DH *dh, int need)
272 * Pollard Rho, Big step/Little Step attacks are O(sqrt(n)), 271 * Pollard Rho, Big step/Little Step attacks are O(sqrt(n)),
273 * so double requested need here. 272 * so double requested need here.
274 */ 273 */
275 dh->length = MIN(need * 2, pbits - 1); 274 dh->length = MINIMUM(need * 2, pbits - 1);
276 if (DH_generate_key(dh) == 0 || 275 if (DH_generate_key(dh) == 0 ||
277 !dh_pub_is_valid(dh, dh->pub_key)) { 276 !dh_pub_is_valid(dh, dh->pub_key)) {
278 BN_clear_free(dh->priv_key); 277 BN_clear_free(dh->priv_key);
diff --git a/gss-genr.c b/gss-genr.c
index d617d600a..62559ed9e 100644
--- a/gss-genr.c
+++ b/gss-genr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gss-genr.c,v 1.23 2015/01/20 23:14:00 deraadt Exp $ */ 1/* $OpenBSD: gss-genr.c,v 1.24 2016/09/12 01:22:38 deraadt Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. 4 * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
@@ -29,7 +29,6 @@
29#ifdef GSSAPI 29#ifdef GSSAPI
30 30
31#include <sys/types.h> 31#include <sys/types.h>
32#include <sys/param.h>
33 32
34#include <limits.h> 33#include <limits.h>
35#include <stdarg.h> 34#include <stdarg.h>
diff --git a/kex.c b/kex.c
index 1e3bdad55..3f08720e3 100644
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.c,v 1.119 2016/09/06 09:14:05 markus Exp $ */ 1/* $OpenBSD: kex.c,v 1.120 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -25,7 +25,6 @@
25 25
26#include "includes.h" 26#include "includes.h"
27 27
28#include <sys/param.h> /* MAX roundup */
29 28
30#include <signal.h> 29#include <signal.h>
31#include <stdarg.h> 30#include <stdarg.h>
@@ -833,14 +832,14 @@ kex_choose_conf(struct ssh *ssh)
833 need = dh_need = 0; 832 need = dh_need = 0;
834 for (mode = 0; mode < MODE_MAX; mode++) { 833 for (mode = 0; mode < MODE_MAX; mode++) {
835 newkeys = kex->newkeys[mode]; 834 newkeys = kex->newkeys[mode];
836 need = MAX(need, newkeys->enc.key_len); 835 need = MAXIMUM(need, newkeys->enc.key_len);
837 need = MAX(need, newkeys->enc.block_size); 836 need = MAXIMUM(need, newkeys->enc.block_size);
838 need = MAX(need, newkeys->enc.iv_len); 837 need = MAXIMUM(need, newkeys->enc.iv_len);
839 need = MAX(need, newkeys->mac.key_len); 838 need = MAXIMUM(need, newkeys->mac.key_len);
840 dh_need = MAX(dh_need, cipher_seclen(newkeys->enc.cipher)); 839 dh_need = MAXIMUM(dh_need, cipher_seclen(newkeys->enc.cipher));
841 dh_need = MAX(dh_need, newkeys->enc.block_size); 840 dh_need = MAXIMUM(dh_need, newkeys->enc.block_size);
842 dh_need = MAX(dh_need, newkeys->enc.iv_len); 841 dh_need = MAXIMUM(dh_need, newkeys->enc.iv_len);
843 dh_need = MAX(dh_need, newkeys->mac.key_len); 842 dh_need = MAXIMUM(dh_need, newkeys->mac.key_len);
844 } 843 }
845 /* XXX need runden? */ 844 /* XXX need runden? */
846 kex->we_need = need; 845 kex->we_need = need;
@@ -871,7 +870,7 @@ derive_key(struct ssh *ssh, int id, u_int need, u_char *hash, u_int hashlen,
871 870
872 if ((mdsz = ssh_digest_bytes(kex->hash_alg)) == 0) 871 if ((mdsz = ssh_digest_bytes(kex->hash_alg)) == 0)
873 return SSH_ERR_INVALID_ARGUMENT; 872 return SSH_ERR_INVALID_ARGUMENT;
874 if ((digest = calloc(1, roundup(need, mdsz))) == NULL) { 873 if ((digest = calloc(1, ROUNDUP(need, mdsz))) == NULL) {
875 r = SSH_ERR_ALLOC_FAIL; 874 r = SSH_ERR_ALLOC_FAIL;
876 goto out; 875 goto out;
877 } 876 }
diff --git a/kexgexc.c b/kexgexc.c
index 71ff13352..ad0d1c8c0 100644
--- a/kexgexc.c
+++ b/kexgexc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexgexc.c,v 1.22 2015/05/26 23:23:40 dtucker Exp $ */ 1/* $OpenBSD: kexgexc.c,v 1.23 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2001 Markus Friedl. All rights reserved.
@@ -28,7 +28,6 @@
28 28
29#ifdef WITH_OPENSSL 29#ifdef WITH_OPENSSL
30 30
31#include <sys/param.h>
32#include <sys/types.h> 31#include <sys/types.h>
33 32
34#include <openssl/dh.h> 33#include <openssl/dh.h>
@@ -50,6 +49,7 @@
50#include "dispatch.h" 49#include "dispatch.h"
51#include "ssherr.h" 50#include "ssherr.h"
52#include "sshbuf.h" 51#include "sshbuf.h"
52#include "misc.h"
53 53
54static int input_kex_dh_gex_group(int, u_int32_t, void *); 54static int input_kex_dh_gex_group(int, u_int32_t, void *);
55static int input_kex_dh_gex_reply(int, u_int32_t, void *); 55static int input_kex_dh_gex_reply(int, u_int32_t, void *);
@@ -67,7 +67,7 @@ kexgex_client(struct ssh *ssh)
67 kex->max = DH_GRP_MAX; 67 kex->max = DH_GRP_MAX;
68 kex->nbits = nbits; 68 kex->nbits = nbits;
69 if (datafellows & SSH_BUG_DHGEX_LARGE) 69 if (datafellows & SSH_BUG_DHGEX_LARGE)
70 kex->nbits = MIN(kex->nbits, 4096); 70 kex->nbits = MINIMUM(kex->nbits, 4096);
71 /* New GEX request */ 71 /* New GEX request */
72 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REQUEST)) != 0 || 72 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REQUEST)) != 0 ||
73 (r = sshpkt_put_u32(ssh, kex->min)) != 0 || 73 (r = sshpkt_put_u32(ssh, kex->min)) != 0 ||
diff --git a/kexgexs.c b/kexgexs.c
index f4400dcbe..449603592 100644
--- a/kexgexs.c
+++ b/kexgexs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexgexs.c,v 1.29 2016/06/08 02:13:01 dtucker Exp $ */ 1/* $OpenBSD: kexgexs.c,v 1.30 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2001 Markus Friedl. All rights reserved.
@@ -28,7 +28,6 @@
28 28
29#ifdef WITH_OPENSSL 29#ifdef WITH_OPENSSL
30 30
31#include <sys/param.h> /* MIN MAX */
32 31
33#include <stdarg.h> 32#include <stdarg.h>
34#include <stdio.h> 33#include <stdio.h>
@@ -53,6 +52,7 @@
53#include "dispatch.h" 52#include "dispatch.h"
54#include "ssherr.h" 53#include "ssherr.h"
55#include "sshbuf.h" 54#include "sshbuf.h"
55#include "misc.h"
56 56
57static int input_kex_dh_gex_request(int, u_int32_t, void *); 57static int input_kex_dh_gex_request(int, u_int32_t, void *);
58static int input_kex_dh_gex_init(int, u_int32_t, void *); 58static 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)
83 kex->nbits = nbits; 83 kex->nbits = nbits;
84 kex->min = min; 84 kex->min = min;
85 kex->max = max; 85 kex->max = max;
86 min = MAX(DH_GRP_MIN, min); 86 min = MAXIMUM(DH_GRP_MIN, min);
87 max = MIN(DH_GRP_MAX, max); 87 max = MINIMUM(DH_GRP_MAX, max);
88 nbits = MAX(DH_GRP_MIN, nbits); 88 nbits = MAXIMUM(DH_GRP_MIN, nbits);
89 nbits = MIN(DH_GRP_MAX, nbits); 89 nbits = MINIMUM(DH_GRP_MAX, nbits);
90 90
91 if (kex->max < kex->min || kex->nbits < kex->min || 91 if (kex->max < kex->min || kex->nbits < kex->min ||
92 kex->max < kex->nbits || kex->max < DH_GRP_MIN) { 92 kex->max < kex->nbits || kex->max < DH_GRP_MIN) {
diff --git a/krl.c b/krl.c
index fff1a3f7c..e271a1934 100644
--- a/krl.c
+++ b/krl.c
@@ -14,11 +14,10 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17/* $OpenBSD: krl.c,v 1.37 2015/12/31 00:33:52 djm Exp $ */ 17/* $OpenBSD: krl.c,v 1.38 2016/09/12 01:22:38 deraadt Exp $ */
18 18
19#include "includes.h" 19#include "includes.h"
20 20
21#include <sys/param.h> /* MIN */
22#include <sys/types.h> 21#include <sys/types.h>
23#include <openbsd-compat/sys-tree.h> 22#include <openbsd-compat/sys-tree.h>
24#include <openbsd-compat/sys-queue.h> 23#include <openbsd-compat/sys-queue.h>
@@ -121,7 +120,7 @@ blob_cmp(struct revoked_blob *a, struct revoked_blob *b)
121 int r; 120 int r;
122 121
123 if (a->len != b->len) { 122 if (a->len != b->len) {
124 if ((r = memcmp(a->blob, b->blob, MIN(a->len, b->len))) != 0) 123 if ((r = memcmp(a->blob, b->blob, MINIMUM(a->len, b->len))) != 0)
125 return r; 124 return r;
126 return a->len > b->len ? 1 : -1; 125 return a->len > b->len ? 1 : -1;
127 } else 126 } else
@@ -458,9 +457,9 @@ choose_next_state(int current_state, u_int64_t contig, int final,
458 * Avoid unsigned overflows. 457 * Avoid unsigned overflows.
459 * The limits are high enough to avoid confusing the calculations. 458 * The limits are high enough to avoid confusing the calculations.
460 */ 459 */
461 contig = MIN(contig, 1ULL<<31); 460 contig = MINIMUM(contig, 1ULL<<31);
462 last_gap = MIN(last_gap, 1ULL<<31); 461 last_gap = MINIMUM(last_gap, 1ULL<<31);
463 next_gap = MIN(next_gap, 1ULL<<31); 462 next_gap = MINIMUM(next_gap, 1ULL<<31);
464 463
465 /* 464 /*
466 * Calculate the cost to switch from the current state to candidates. 465 * 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,
486 /* Estimate base cost in bits of each section type */ 485 /* Estimate base cost in bits of each section type */
487 cost_list += 64 * contig + (final ? 0 : 8+64); 486 cost_list += 64 * contig + (final ? 0 : 8+64);
488 cost_range += (2 * 64) + (final ? 0 : 8+64); 487 cost_range += (2 * 64) + (final ? 0 : 8+64);
489 cost_bitmap += last_gap + contig + (final ? 0 : MIN(next_gap, 8+64)); 488 cost_bitmap += last_gap + contig + (final ? 0 : MINIMUM(next_gap, 8+64));
490 cost_bitmap_restart += contig + (final ? 0 : MIN(next_gap, 8+64)); 489 cost_bitmap_restart += contig + (final ? 0 : MINIMUM(next_gap, 8+64));
491 490
492 /* Convert to byte costs for actual comparison */ 491 /* Convert to byte costs for actual comparison */
493 cost_list = (cost_list + 7) / 8; 492 cost_list = (cost_list + 7) / 8;
diff --git a/misc.h b/misc.h
index ef375577c..8f954198b 100644
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.h,v 1.58 2016/08/27 04:05:12 guenther Exp $ */ 1/* $OpenBSD: misc.h,v 1.59 2016/09/12 01:22:38 deraadt Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -141,4 +141,8 @@ char *read_passphrase(const char *, int);
141int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2))); 141int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2)));
142int read_keyfile_line(FILE *, const char *, char *, size_t, u_long *); 142int read_keyfile_line(FILE *, const char *, char *, size_t, u_long *);
143 143
144#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
145#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
146#define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
147
144#endif /* _MISC_H */ 148#endif /* _MISC_H */
diff --git a/moduli.c b/moduli.c
index ed1bdc946..e983b07b7 100644
--- a/moduli.c
+++ b/moduli.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: moduli.c,v 1.30 2015/01/20 23:14:00 deraadt Exp $ */ 1/* $OpenBSD: moduli.c,v 1.31 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright 1994 Phil Karn <karn@qualcomm.com> 3 * Copyright 1994 Phil Karn <karn@qualcomm.com>
4 * Copyright 1996-1998, 2003 William Allen Simpson <wsimpson@greendragon.com> 4 * Copyright 1996-1998, 2003 William Allen Simpson <wsimpson@greendragon.com>
@@ -41,7 +41,6 @@
41 41
42#ifdef WITH_OPENSSL 42#ifdef WITH_OPENSSL
43 43
44#include <sys/param.h> /* MAX */
45#include <sys/types.h> 44#include <sys/types.h>
46 45
47#include <openssl/bn.h> 46#include <openssl/bn.h>
@@ -609,7 +608,7 @@ prime_test(FILE *in, FILE *out, u_int32_t trials, u_int32_t generator_wanted,
609 608
610 if (checkpoint_file != NULL) 609 if (checkpoint_file != NULL)
611 last_processed = read_checkpoint(checkpoint_file); 610 last_processed = read_checkpoint(checkpoint_file);
612 last_processed = start_lineno = MAX(last_processed, start_lineno); 611 last_processed = start_lineno = MAXIMUM(last_processed, start_lineno);
613 if (end_lineno == ULONG_MAX) 612 if (end_lineno == ULONG_MAX)
614 debug("process from line %lu from pipe", last_processed); 613 debug("process from line %lu from pipe", last_processed);
615 else 614 else
diff --git a/packet.c b/packet.c
index 9ee23147e..711091da7 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.c,v 1.236 2016/09/06 09:22:56 markus Exp $ */ 1/* $OpenBSD: packet.c,v 1.237 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -38,8 +38,7 @@
38 */ 38 */
39 39
40#include "includes.h" 40#include "includes.h"
41 41
42#include <sys/param.h> /* MIN roundup */
43#include <sys/types.h> 42#include <sys/types.h>
44#include "openbsd-compat/sys-queue.h" 43#include "openbsd-compat/sys-queue.h"
45#include <sys/socket.h> 44#include <sys/socket.h>
@@ -1069,7 +1068,7 @@ ssh_set_newkeys(struct ssh *ssh, int mode)
1069 else 1068 else
1070 *max_blocks = ((u_int64_t)1 << 30) / enc->block_size; 1069 *max_blocks = ((u_int64_t)1 << 30) / enc->block_size;
1071 if (state->rekey_limit) 1070 if (state->rekey_limit)
1072 *max_blocks = MIN(*max_blocks, 1071 *max_blocks = MINIMUM(*max_blocks,
1073 state->rekey_limit / enc->block_size); 1072 state->rekey_limit / enc->block_size);
1074 debug("rekey after %llu blocks", (unsigned long long)*max_blocks); 1073 debug("rekey after %llu blocks", (unsigned long long)*max_blocks);
1075 return 0; 1074 return 0;
@@ -1112,7 +1111,7 @@ ssh_packet_need_rekeying(struct ssh *ssh, u_int outbound_packet_len)
1112 return 1; 1111 return 1;
1113 1112
1114 /* Rekey after (cipher-specific) maxiumum blocks */ 1113 /* Rekey after (cipher-specific) maxiumum blocks */
1115 out_blocks = roundup(outbound_packet_len, 1114 out_blocks = ROUNDUP(outbound_packet_len,
1116 state->newkeys[MODE_OUT]->enc.block_size); 1115 state->newkeys[MODE_OUT]->enc.block_size);
1117 return (state->max_blocks_out && 1116 return (state->max_blocks_out &&
1118 (state->p_send.blocks + out_blocks > state->max_blocks_out)) || 1117 (state->p_send.blocks + out_blocks > state->max_blocks_out)) ||
@@ -1240,7 +1239,7 @@ ssh_packet_send2_wrapped(struct ssh *ssh)
1240 if (state->extra_pad) { 1239 if (state->extra_pad) {
1241 tmp = state->extra_pad; 1240 tmp = state->extra_pad;
1242 state->extra_pad = 1241 state->extra_pad =
1243 roundup(state->extra_pad, block_size); 1242 ROUNDUP(state->extra_pad, block_size);
1244 /* check if roundup overflowed */ 1243 /* check if roundup overflowed */
1245 if (state->extra_pad < tmp) 1244 if (state->extra_pad < tmp)
1246 return SSH_ERR_INVALID_ARGUMENT; 1245 return SSH_ERR_INVALID_ARGUMENT;
diff --git a/sandbox-rlimit.c b/sandbox-rlimit.c
index bba80778b..0bff3dfba 100644
--- a/sandbox-rlimit.c
+++ b/sandbox-rlimit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sandbox-rlimit.c,v 1.3 2011/06/23 09:34:13 djm Exp $ */ 1/* $OpenBSD: sandbox-rlimit.c,v 1.4 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -20,7 +20,6 @@
20#ifdef SANDBOX_RLIMIT 20#ifdef SANDBOX_RLIMIT
21 21
22#include <sys/types.h> 22#include <sys/types.h>
23#include <sys/param.h>
24#include <sys/time.h> 23#include <sys/time.h>
25#include <sys/resource.h> 24#include <sys/resource.h>
26 25
diff --git a/scp.c b/scp.c
index 43ca3fa09..c67cd71df 100644
--- a/scp.c
+++ b/scp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: scp.c,v 1.186 2016/05/25 23:48:45 schwarze Exp $ */ 1/* $OpenBSD: scp.c,v 1.187 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * scp - secure remote copy. This is basically patched BSD rcp which 3 * scp - secure remote copy. This is basically patched BSD rcp which
4 * uses ssh to do the data transfer (instead of using rcmd). 4 * uses ssh to do the data transfer (instead of using rcmd).
@@ -74,7 +74,6 @@
74#include "includes.h" 74#include "includes.h"
75 75
76#include <sys/types.h> 76#include <sys/types.h>
77#include <sys/param.h>
78#ifdef HAVE_SYS_STAT_H 77#ifdef HAVE_SYS_STAT_H
79# include <sys/stat.h> 78# include <sys/stat.h>
80#endif 79#endif
@@ -383,7 +382,7 @@ main(int argc, char **argv)
383 setlocale(LC_CTYPE, ""); 382 setlocale(LC_CTYPE, "");
384 383
385 /* Copy argv, because we modify it */ 384 /* Copy argv, because we modify it */
386 newargv = xcalloc(MAX(argc + 1, 1), sizeof(*newargv)); 385 newargv = xcalloc(MAXIMUM(argc + 1, 1), sizeof(*newargv));
387 for (n = 0; n < argc; n++) 386 for (n = 0; n < argc; n++)
388 newargv[n] = xstrdup(argv[n]); 387 newargv[n] = xstrdup(argv[n]);
389 argv = newargv; 388 argv = newargv;
@@ -1343,7 +1342,7 @@ allocbuf(BUF *bp, int fd, int blksize)
1343 run_err("fstat: %s", strerror(errno)); 1342 run_err("fstat: %s", strerror(errno));
1344 return (0); 1343 return (0);
1345 } 1344 }
1346 size = roundup(stb.st_blksize, blksize); 1345 size = ROUNDUP(stb.st_blksize, blksize);
1347 if (size == 0) 1346 if (size == 0)
1348 size = blksize; 1347 size = blksize;
1349#else /* HAVE_STRUCT_STAT_ST_BLKSIZE */ 1348#else /* HAVE_STRUCT_STAT_ST_BLKSIZE */
diff --git a/serverloop.c b/serverloop.c
index 1e211701e..87e619fe4 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: serverloop.c,v 1.185 2016/08/13 17:47:41 markus Exp $ */ 1/* $OpenBSD: serverloop.c,v 1.186 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -37,7 +37,6 @@
37 37
38#include "includes.h" 38#include "includes.h"
39 39
40#include <sys/param.h> /* MIN MAX */
41#include <sys/types.h> 40#include <sys/types.h>
42#include <sys/wait.h> 41#include <sys/wait.h>
43#include <sys/socket.h> 42#include <sys/socket.h>
@@ -212,7 +211,7 @@ wait_until_can_do_something(int connection_in, int connection_out,
212 211
213 /* XXX need proper deadline system for rekey/client alive */ 212 /* XXX need proper deadline system for rekey/client alive */
214 if (minwait_secs != 0) 213 if (minwait_secs != 0)
215 max_time_ms = MIN(max_time_ms, (u_int)minwait_secs * 1000); 214 max_time_ms = MINIMUM(max_time_ms, (u_int)minwait_secs * 1000);
216 215
217 /* 216 /*
218 * if using client_alive, set the max timeout accordingly, 217 * if using client_alive, set the max timeout accordingly,
@@ -372,8 +371,8 @@ server_loop2(Authctxt *authctxt)
372 371
373 notify_setup(); 372 notify_setup();
374 373
375 max_fd = MAX(connection_in, connection_out); 374 max_fd = MAXIMUM(connection_in, connection_out);
376 max_fd = MAX(max_fd, notify_pipe[0]); 375 max_fd = MAXIMUM(max_fd, notify_pipe[0]);
377 376
378 server_init_dispatch(); 377 server_init_dispatch();
379 378
diff --git a/sftp-client.c b/sftp-client.c
index 0ca44a4d6..e65c15c8f 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.c,v 1.124 2016/05/25 23:48:45 schwarze Exp $ */ 1/* $OpenBSD: sftp-client.c,v 1.125 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -22,7 +22,6 @@
22 22
23#include "includes.h" 23#include "includes.h"
24 24
25#include <sys/param.h> /* MIN MAX */
26#include <sys/types.h> 25#include <sys/types.h>
27#ifdef HAVE_SYS_STATVFS_H 26#ifdef HAVE_SYS_STATVFS_H
28#include <sys/statvfs.h> 27#include <sys/statvfs.h>
@@ -462,7 +461,7 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests,
462 461
463 /* Some filexfer v.0 servers don't support large packets */ 462 /* Some filexfer v.0 servers don't support large packets */
464 if (ret->version == 0) 463 if (ret->version == 0)
465 ret->transfer_buflen = MIN(ret->transfer_buflen, 20480); 464 ret->transfer_buflen = MINIMUM(ret->transfer_buflen, 20480);
466 465
467 ret->limit_kbps = limit_kbps; 466 ret->limit_kbps = limit_kbps;
468 if (ret->limit_kbps > 0) { 467 if (ret->limit_kbps > 0) {
@@ -1351,7 +1350,7 @@ do_download(struct sftp_conn *conn, const char *remote_path,
1351 req->offset, req->len, handle, handle_len); 1350 req->offset, req->len, handle, handle_len);
1352 /* Reduce the request size */ 1351 /* Reduce the request size */
1353 if (len < buflen) 1352 if (len < buflen)
1354 buflen = MAX(MIN_READ_SIZE, len); 1353 buflen = MAXIMUM(MIN_READ_SIZE, len);
1355 } 1354 }
1356 if (max_req > 0) { /* max_req = 0 iff EOF received */ 1355 if (max_req > 0) { /* max_req = 0 iff EOF received */
1357 if (size > 0 && offset > size) { 1356 if (size > 0 && offset > size) {
diff --git a/sftp-common.c b/sftp-common.c
index 9dc1f9831..3a70c52dd 100644
--- a/sftp-common.c
+++ b/sftp-common.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-common.c,v 1.28 2015/01/20 23:14:00 deraadt Exp $ */ 1/* $OpenBSD: sftp-common.c,v 1.29 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2001 Damien Miller. All rights reserved. 4 * Copyright (c) 2001 Damien Miller. All rights reserved.
@@ -26,7 +26,6 @@
26 26
27#include "includes.h" 27#include "includes.h"
28 28
29#include <sys/param.h> /* MAX */
30#include <sys/types.h> 29#include <sys/types.h>
31#include <sys/stat.h> 30#include <sys/stat.h>
32 31
@@ -45,6 +44,7 @@
45#include "ssherr.h" 44#include "ssherr.h"
46#include "sshbuf.h" 45#include "sshbuf.h"
47#include "log.h" 46#include "log.h"
47#include "misc.h"
48 48
49#include "sftp.h" 49#include "sftp.h"
50#include "sftp-common.h" 50#include "sftp-common.h"
@@ -243,8 +243,8 @@ ls_file(const char *name, const struct stat *st, int remote, int si_units)
243 } 243 }
244 if (sz == 0) 244 if (sz == 0)
245 tbuf[0] = '\0'; 245 tbuf[0] = '\0';
246 ulen = MAX(strlen(user), 8); 246 ulen = MAXIMUM(strlen(user), 8);
247 glen = MAX(strlen(group), 8); 247 glen = MAXIMUM(strlen(group), 8);
248 if (si_units) { 248 if (si_units) {
249 fmt_scaled((long long)st->st_size, sbuf); 249 fmt_scaled((long long)st->st_size, sbuf);
250 snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8s %s %s", mode, 250 snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8s %s %s", mode,
diff --git a/sftp-server.c b/sftp-server.c
index 646286a3c..3619cdfc0 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-server.c,v 1.109 2016/02/15 09:47:49 dtucker Exp $ */ 1/* $OpenBSD: sftp-server.c,v 1.110 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000-2004 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000-2004 Markus Friedl. All rights reserved.
4 * 4 *
@@ -17,7 +17,6 @@
17 17
18#include "includes.h" 18#include "includes.h"
19 19
20#include <sys/param.h> /* MIN */
21#include <sys/types.h> 20#include <sys/types.h>
22#include <sys/stat.h> 21#include <sys/stat.h>
23#ifdef HAVE_SYS_TIME_H 22#ifdef HAVE_SYS_TIME_H
@@ -505,7 +504,7 @@ status_to_message(u_int32_t status)
505 "Operation unsupported", /* SSH_FX_OP_UNSUPPORTED */ 504 "Operation unsupported", /* SSH_FX_OP_UNSUPPORTED */
506 "Unknown error" /* Others */ 505 "Unknown error" /* Others */
507 }; 506 };
508 return (status_messages[MIN(status,SSH2_FX_MAX)]); 507 return (status_messages[MINIMUM(status,SSH2_FX_MAX)]);
509} 508}
510 509
511static void 510static void
diff --git a/sftp.c b/sftp.c
index 08e13a733..1b5c92498 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.175 2016/07/22 03:47:36 djm Exp $ */ 1/* $OpenBSD: sftp.c,v 1.176 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -17,7 +17,6 @@
17 17
18#include "includes.h" 18#include "includes.h"
19 19
20#include <sys/param.h> /* MIN MAX */
21#include <sys/types.h> 20#include <sys/types.h>
22#include <sys/ioctl.h> 21#include <sys/ioctl.h>
23#ifdef HAVE_SYS_STAT_H 22#ifdef HAVE_SYS_STAT_H
@@ -802,7 +801,7 @@ do_ls_dir(struct sftp_conn *conn, const char *path,
802 /* Count entries for sort and find longest filename */ 801 /* Count entries for sort and find longest filename */
803 for (n = 0; d[n] != NULL; n++) { 802 for (n = 0; d[n] != NULL; n++) {
804 if (d[n]->filename[0] != '.' || (lflag & LS_SHOW_ALL)) 803 if (d[n]->filename[0] != '.' || (lflag & LS_SHOW_ALL))
805 m = MAX(m, strlen(d[n]->filename)); 804 m = MAXIMUM(m, strlen(d[n]->filename));
806 } 805 }
807 806
808 /* Add any subpath that also needs to be counted */ 807 /* Add any subpath that also needs to be counted */
@@ -814,9 +813,9 @@ do_ls_dir(struct sftp_conn *conn, const char *path,
814 width = ws.ws_col; 813 width = ws.ws_col;
815 814
816 columns = width / (m + 2); 815 columns = width / (m + 2);
817 columns = MAX(columns, 1); 816 columns = MAXIMUM(columns, 1);
818 colspace = width / columns; 817 colspace = width / columns;
819 colspace = MIN(colspace, width); 818 colspace = MINIMUM(colspace, width);
820 } 819 }
821 820
822 if (lflag & SORT_FLAGS) { 821 if (lflag & SORT_FLAGS) {
@@ -915,10 +914,10 @@ do_globbed_ls(struct sftp_conn *conn, const char *path,
915 if (!(lflag & LS_SHORT_VIEW)) { 914 if (!(lflag & LS_SHORT_VIEW)) {
916 /* Count entries for sort and find longest filename */ 915 /* Count entries for sort and find longest filename */
917 for (i = 0; g.gl_pathv[i]; i++) 916 for (i = 0; g.gl_pathv[i]; i++)
918 m = MAX(m, strlen(g.gl_pathv[i])); 917 m = MAXIMUM(m, strlen(g.gl_pathv[i]));
919 918
920 columns = width / (m + 2); 919 columns = width / (m + 2);
921 columns = MAX(columns, 1); 920 columns = MAXIMUM(columns, 1);
922 colspace = width / columns; 921 colspace = width / columns;
923 } 922 }
924 923
@@ -1669,16 +1668,16 @@ complete_display(char **list, u_int len)
1669 1668
1670 /* Count entries for sort and find longest */ 1669 /* Count entries for sort and find longest */
1671 for (y = 0; list[y]; y++) 1670 for (y = 0; list[y]; y++)
1672 m = MAX(m, strlen(list[y])); 1671 m = MAXIMUM(m, strlen(list[y]));
1673 1672
1674 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1) 1673 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
1675 width = ws.ws_col; 1674 width = ws.ws_col;
1676 1675
1677 m = m > len ? m - len : 0; 1676 m = m > len ? m - len : 0;
1678 columns = width / (m + 2); 1677 columns = width / (m + 2);
1679 columns = MAX(columns, 1); 1678 columns = MAXIMUM(columns, 1);
1680 colspace = width / columns; 1679 colspace = width / columns;
1681 colspace = MIN(colspace, width); 1680 colspace = MINIMUM(colspace, width);
1682 1681
1683 printf("\n"); 1682 printf("\n");
1684 m = 1; 1683 m = 1;
diff --git a/ssh-agent.c b/ssh-agent.c
index 25d6ebc53..fd5f2b35d 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-agent.c,v 1.213 2016/05/02 08:49:03 djm Exp $ */ 1/* $OpenBSD: ssh-agent.c,v 1.214 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -36,7 +36,6 @@
36 36
37#include "includes.h" 37#include "includes.h"
38 38
39#include <sys/param.h> /* MIN MAX */
40#include <sys/types.h> 39#include <sys/types.h>
41#include <sys/param.h> 40#include <sys/param.h>
42#include <sys/resource.h> 41#include <sys/resource.h>
@@ -539,7 +538,7 @@ reaper(void)
539 tab->nentries--; 538 tab->nentries--;
540 } else 539 } else
541 deadline = (deadline == 0) ? id->death : 540 deadline = (deadline == 0) ? id->death :
542 MIN(deadline, id->death); 541 MINIMUM(deadline, id->death);
543 } 542 }
544 } 543 }
545 if (deadline == 0 || deadline <= now) 544 if (deadline == 0 || deadline <= now)
@@ -991,7 +990,7 @@ prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, u_int *nallocp,
991 switch (sockets[i].type) { 990 switch (sockets[i].type) {
992 case AUTH_SOCKET: 991 case AUTH_SOCKET:
993 case AUTH_CONNECTION: 992 case AUTH_CONNECTION:
994 n = MAX(n, sockets[i].fd); 993 n = MAXIMUM(n, sockets[i].fd);
995 break; 994 break;
996 case AUTH_UNUSED: 995 case AUTH_UNUSED:
997 break; 996 break;
@@ -1030,7 +1029,7 @@ prepare_select(fd_set **fdrp, fd_set **fdwp, int *fdl, u_int *nallocp,
1030 deadline = reaper(); 1029 deadline = reaper();
1031 if (parent_alive_interval != 0) 1030 if (parent_alive_interval != 0)
1032 deadline = (deadline == 0) ? parent_alive_interval : 1031 deadline = (deadline == 0) ? parent_alive_interval :
1033 MIN(deadline, parent_alive_interval); 1032 MINIMUM(deadline, parent_alive_interval);
1034 if (deadline == 0) { 1033 if (deadline == 0) {
1035 *tvpp = NULL; 1034 *tvpp = NULL;
1036 } else { 1035 } else {
diff --git a/sshbuf.c b/sshbuf.c
index 4d6e0ea0a..91cbd067c 100644
--- a/sshbuf.c
+++ b/sshbuf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshbuf.c,v 1.6 2016/01/12 23:42:54 djm Exp $ */ 1/* $OpenBSD: sshbuf.c,v 1.7 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller 3 * Copyright (c) 2011 Damien Miller
4 * 4 *
@@ -18,7 +18,6 @@
18#define SSHBUF_INTERNAL 18#define SSHBUF_INTERNAL
19#include "includes.h" 19#include "includes.h"
20 20
21#include <sys/param.h> /* roundup */
22#include <sys/types.h> 21#include <sys/types.h>
23#include <signal.h> 22#include <signal.h>
24#include <stdlib.h> 23#include <stdlib.h>
@@ -27,6 +26,7 @@
27 26
28#include "ssherr.h" 27#include "ssherr.h"
29#include "sshbuf.h" 28#include "sshbuf.h"
29#include "misc.h"
30 30
31static inline int 31static inline int
32sshbuf_check_sanity(const struct sshbuf *buf) 32sshbuf_check_sanity(const struct sshbuf *buf)
@@ -250,7 +250,7 @@ sshbuf_set_max_size(struct sshbuf *buf, size_t max_size)
250 if (buf->size < SSHBUF_SIZE_INIT) 250 if (buf->size < SSHBUF_SIZE_INIT)
251 rlen = SSHBUF_SIZE_INIT; 251 rlen = SSHBUF_SIZE_INIT;
252 else 252 else
253 rlen = roundup(buf->size, SSHBUF_SIZE_INC); 253 rlen = ROUNDUP(buf->size, SSHBUF_SIZE_INC);
254 if (rlen > max_size) 254 if (rlen > max_size)
255 rlen = max_size; 255 rlen = max_size;
256 explicit_bzero(buf->d + buf->size, buf->alloc - buf->size); 256 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)
340 * allocate less if doing so would overflow max_size. 340 * allocate less if doing so would overflow max_size.
341 */ 341 */
342 need = len + buf->size - buf->alloc; 342 need = len + buf->size - buf->alloc;
343 rlen = roundup(buf->alloc + need, SSHBUF_SIZE_INC); 343 rlen = ROUNDUP(buf->alloc + need, SSHBUF_SIZE_INC);
344 SSHBUF_DBG(("need %zu initial rlen %zu", need, rlen)); 344 SSHBUF_DBG(("need %zu initial rlen %zu", need, rlen));
345 if (rlen > buf->max_size) 345 if (rlen > buf->max_size)
346 rlen = buf->alloc + need; 346 rlen = buf->alloc + need;
diff --git a/sshconnect.c b/sshconnect.c
index 356ec79f0..96b91ce1a 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.271 2016/01/14 22:56:56 markus Exp $ */ 1/* $OpenBSD: sshconnect.c,v 1.272 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -15,7 +15,6 @@
15 15
16#include "includes.h" 16#include "includes.h"
17 17
18#include <sys/param.h> /* roundup */
19#include <sys/types.h> 18#include <sys/types.h>
20#include <sys/wait.h> 19#include <sys/wait.h>
21#include <sys/stat.h> 20#include <sys/stat.h>
@@ -1403,7 +1402,7 @@ ssh_put_password(char *password)
1403 packet_put_cstring(password); 1402 packet_put_cstring(password);
1404 return; 1403 return;
1405 } 1404 }
1406 size = roundup(strlen(password) + 1, 32); 1405 size = ROUNDUP(strlen(password) + 1, 32);
1407 padded = xcalloc(1, size); 1406 padded = xcalloc(1, size);
1408 strlcpy(padded, password, size); 1407 strlcpy(padded, password, size);
1409 packet_put_string(padded, size); 1408 packet_put_string(padded, size);
diff --git a/sshkey.c b/sshkey.c
index 166ac714d..8f6173e27 100644
--- a/sshkey.c
+++ b/sshkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshkey.c,v 1.36 2016/08/03 05:41:57 djm Exp $ */ 1/* $OpenBSD: sshkey.c,v 1.37 2016/09/12 01:22:38 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2008 Alexander von Gernler. All rights reserved. 4 * Copyright (c) 2008 Alexander von Gernler. All rights reserved.
@@ -27,7 +27,6 @@
27 27
28#include "includes.h" 28#include "includes.h"
29 29
30#include <sys/param.h> /* MIN MAX */
31#include <sys/types.h> 30#include <sys/types.h>
32#include <netinet/in.h> 31#include <netinet/in.h>
33 32
@@ -1082,10 +1081,10 @@ fingerprint_randomart(const char *alg, u_char *dgst_raw, size_t dgst_raw_len,
1082 y += (input & 0x2) ? 1 : -1; 1081 y += (input & 0x2) ? 1 : -1;
1083 1082
1084 /* assure we are still in bounds */ 1083 /* assure we are still in bounds */
1085 x = MAX(x, 0); 1084 x = MAXIMUM(x, 0);
1086 y = MAX(y, 0); 1085 y = MAXIMUM(y, 0);
1087 x = MIN(x, FLDSIZE_X - 1); 1086 x = MINIMUM(x, FLDSIZE_X - 1);
1088 y = MIN(y, FLDSIZE_Y - 1); 1087 y = MINIMUM(y, FLDSIZE_Y - 1);
1089 1088
1090 /* augment the field */ 1089 /* augment the field */
1091 if (field[x][y] < len - 2) 1090 if (field[x][y] < len - 2)
@@ -1126,7 +1125,7 @@ fingerprint_randomart(const char *alg, u_char *dgst_raw, size_t dgst_raw_len,
1126 for (y = 0; y < FLDSIZE_Y; y++) { 1125 for (y = 0; y < FLDSIZE_Y; y++) {
1127 *p++ = '|'; 1126 *p++ = '|';
1128 for (x = 0; x < FLDSIZE_X; x++) 1127 for (x = 0; x < FLDSIZE_X; x++)
1129 *p++ = augmentation_string[MIN(field[x][y], len)]; 1128 *p++ = augmentation_string[MINIMUM(field[x][y], len)];
1130 *p++ = '|'; 1129 *p++ = '|';
1131 *p++ = '\n'; 1130 *p++ = '\n';
1132 } 1131 }