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
This commit is contained in:
deraadt@openbsd.org 2016-09-12 01:22:38 +00:00 коммит произвёл Darren Tucker
Родитель f219fc8f03
Коммит 9136ec134c
22 изменённых файлов: 101 добавлений и 114 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;

5
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);

Просмотреть файл

@ -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>

21
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;
}

Просмотреть файл

@ -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 ||

Просмотреть файл

@ -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) {

15
krl.c
Просмотреть файл

@ -14,11 +14,10 @@
* 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;

6
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 */

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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>

7
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 */

Просмотреть файл

@ -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();

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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,

Просмотреть файл

@ -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

19
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;

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);

Просмотреть файл

@ -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';
}