From ef095ce00ab8e6ff4257839b6fedc2efcbc80ea8 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Wed, 14 May 2003 13:41:39 +1000 Subject: - markus@cvs.openbsd.org 2003/04/12 10:15:36 [misc.c] debug->debug2 --- misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc.c') diff --git a/misc.c b/misc.c index 512fb22fb..ff1966192 100644 --- a/misc.c +++ b/misc.c @@ -23,7 +23,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: misc.c,v 1.20 2002/12/13 10:03:15 markus Exp $"); +RCSID("$OpenBSD: misc.c,v 1.21 2003/04/12 10:15:36 markus Exp $"); #include "misc.h" #include "log.h" @@ -60,7 +60,7 @@ set_nonblock(int fd) debug2("fd %d is O_NONBLOCK", fd); return; } - debug("fd %d setting O_NONBLOCK", fd); + debug2("fd %d setting O_NONBLOCK", fd); val |= O_NONBLOCK; if (fcntl(fd, F_SETFL, val) == -1) debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", -- cgit v1.2.3 From 5ade9abc37df3dacacbe20104877ca6dab61082a Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Mon, 25 Aug 2003 01:16:21 +0000 Subject: - (bal) redo how we handle 'mysignal()'. Move it to openbsd-compat/bsd-misc.c, s/mysignal/signal/ and #define signal to be our 'mysignal' by default. OK djm@ --- ChangeLog | 7 +++++-- entropy.c | 6 +++--- misc.c | 26 -------------------------- misc.h | 4 ---- openbsd-compat/bsd-misc.c | 28 +++++++++++++++++++++++++++- openbsd-compat/bsd-misc.h | 8 +++++++- progressmeter.c | 4 ++-- sshd.c | 4 ++-- sshpty.c | 12 ++++++------ 9 files changed, 52 insertions(+), 47 deletions(-) (limited to 'misc.c') diff --git a/ChangeLog b/ChangeLog index 956a5e3a8..6ea448a37 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,10 @@ - (djm) Bug #621: Select OpenSC keys by usage attributes. Patch from larsch@trustcenter.de - (bal) openbsd-compat/ OpenBSD updates. Mostly licensing, ansifications - and minor fixes. + and minor fixes. OK djm@ + - (bal) redo how we handle 'mysignal()'. Move it to + openbsd-compat/bsd-misc.c, s/mysignal/signal/ and #define signal to + be our 'mysignal' by default. OK djm@ 20030822 - (djm) s/get_progname/ssh_get_progname/g to avoid conflict with Heimdal @@ -857,4 +860,4 @@ - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo. Report from murple@murple.net, diagnosis from dtucker@zip.com.au -$Id: ChangeLog,v 1.2900 2003/08/25 01:10:51 mouring Exp $ +$Id: ChangeLog,v 1.2901 2003/08/25 01:16:21 mouring Exp $ diff --git a/entropy.c b/entropy.c index a16ea10b3..216879786 100644 --- a/entropy.c +++ b/entropy.c @@ -45,7 +45,7 @@ * XXX: we should tell the child how many bytes we need. */ -RCSID("$Id: entropy.c,v 1.45 2003/05/16 05:51:45 djm Exp $"); +RCSID("$Id: entropy.c,v 1.46 2003/08/25 01:16:21 mouring Exp $"); #ifndef OPENSSL_PRNG_ONLY #define RANDOM_SEED_SIZE 48 @@ -75,7 +75,7 @@ seed_rng(void) if (pipe(p) == -1) fatal("pipe: %s", strerror(errno)); - old_sigchld = mysignal(SIGCHLD, SIG_DFL); + old_sigchld = signal(SIGCHLD, SIG_DFL); if ((pid = fork()) == -1) fatal("Couldn't fork: %s", strerror(errno)); if (pid == 0) { @@ -116,7 +116,7 @@ seed_rng(void) if (waitpid(pid, &ret, 0) == -1) fatal("Couldn't wait for ssh-rand-helper completion: %s", strerror(errno)); - mysignal(SIGCHLD, old_sigchld); + signal(SIGCHLD, old_sigchld); /* We don't mind if the child exits upon a SIGPIPE */ if (!WIFEXITED(ret) && diff --git a/misc.c b/misc.c index ff1966192..c457a952c 100644 --- a/misc.c +++ b/misc.c @@ -323,29 +323,3 @@ addargs(arglist *args, char *fmt, ...) args->list[args->num++] = xstrdup(buf); args->list[args->num] = NULL; } - -mysig_t -mysignal(int sig, mysig_t act) -{ -#ifdef HAVE_SIGACTION - struct sigaction sa, osa; - - if (sigaction(sig, NULL, &osa) == -1) - return (mysig_t) -1; - if (osa.sa_handler != act) { - memset(&sa, 0, sizeof(sa)); - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; -#if defined(SA_INTERRUPT) - if (sig == SIGALRM) - sa.sa_flags |= SA_INTERRUPT; -#endif - sa.sa_handler = act; - if (sigaction(sig, &sa, NULL) == -1) - return (mysig_t) -1; - } - return (osa.sa_handler); -#else - return (signal(sig, act)); -#endif -} diff --git a/misc.h b/misc.h index 3b4b87967..6d2869b36 100644 --- a/misc.h +++ b/misc.h @@ -31,7 +31,3 @@ struct arglist { int nalloc; }; void addargs(arglist *, char *, ...) __attribute__((format(printf, 2, 3))); - -/* wrapper for signal interface */ -typedef void (*mysig_t)(int); -mysig_t mysignal(int sig, mysig_t act); diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 56cb45ade..08b089bdc 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.18 2003/08/21 23:34:42 djm Exp $"); +RCSID("$Id: bsd-misc.c,v 1.19 2003/08/25 01:16:21 mouring Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -200,3 +200,29 @@ tcsendbreak(int fd, int duration) # endif } #endif /* HAVE_TCSENDBREAK */ + +mysig_t +mysignal(int sig, mysig_t act) +{ +#ifdef HAVE_SIGACTION + struct sigaction sa, osa; + + if (sigaction(sig, NULL, &osa) == -1) + return (mysig_t) -1; + if (osa.sa_handler != act) { + memset(&sa, 0, sizeof(sa)); + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; +#ifdef SA_INTERRUPT + if (sig == SIGALRM) + sa.sa_flags |= SA_INTERRUPT; +#endif + sa.sa_handler = act; + if (sigaction(sig, &sa, NULL) == -1) + return (mysig_t) -1; + } + return (osa.sa_handler); +#else + return (signal(sig, act)); +#endif +} diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 2857de59b..0d6076ab0 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: bsd-misc.h,v 1.11 2003/08/21 23:34:42 djm Exp $ */ +/* $Id: bsd-misc.h,v 1.12 2003/08/25 01:16:22 mouring Exp $ */ #ifndef _BSD_MISC_H #define _BSD_MISC_H @@ -97,4 +97,10 @@ pid_t tcgetpgrp(int); int tcsendbreak(int, int); #endif +/* wrapper for signal interface */ +typedef void (*mysig_t)(int); +mysig_t mysignal(int sig, mysig_t act); + +#define signal(a,b) mysignal(a,b) + #endif /* _BSD_MISC_H */ diff --git a/progressmeter.c b/progressmeter.c index 170d869f4..9fe8cfa41 100644 --- a/progressmeter.c +++ b/progressmeter.c @@ -212,7 +212,7 @@ update_progress_meter(int ignore) if (can_output()) refresh_progress_meter(); - mysignal(SIGALRM, update_progress_meter); + signal(SIGALRM, update_progress_meter); alarm(UPDATE_INTERVAL); errno = save_errno; } @@ -243,7 +243,7 @@ start_progress_meter(char *f, off_t filesize, off_t *stat) if (can_output()) refresh_progress_meter(); - mysignal(SIGALRM, update_progress_meter); + signal(SIGALRM, update_progress_meter); alarm(UPDATE_INTERVAL); } diff --git a/sshd.c b/sshd.c index 0e1bde3a3..8d04f6a74 100644 --- a/sshd.c +++ b/sshd.c @@ -1368,7 +1368,7 @@ main(int ac, char **av) if ((options.protocol & SSH_PROTO_1) && key_used == 0) { /* Schedule server key regeneration alarm. */ - mysignal(SIGALRM, key_regeneration_alarm); + signal(SIGALRM, key_regeneration_alarm); alarm(options.key_regeneration_time); key_used = 1; } @@ -1457,7 +1457,7 @@ main(int ac, char **av) * mode; it is just annoying to have the server exit just when you * are about to discover the bug. */ - mysignal(SIGALRM, grace_alarm_handler); + signal(SIGALRM, grace_alarm_handler); if (!debug_flag) alarm(options.login_grace_time); diff --git a/sshpty.c b/sshpty.c index 109fc96ac..4747ceaf4 100644 --- a/sshpty.c +++ b/sshpty.c @@ -101,12 +101,12 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen) error("/dev/ptmx: %.100s", strerror(errno)); return 0; } - old_signal = mysignal(SIGCHLD, SIG_DFL); + old_signal = signal(SIGCHLD, SIG_DFL); if (grantpt(ptm) < 0) { error("grantpt: %.100s", strerror(errno)); return 0; } - mysignal(SIGCHLD, old_signal); + signal(SIGCHLD, old_signal); if (unlockpt(ptm) < 0) { error("unlockpt: %.100s", strerror(errno)); return 0; @@ -274,9 +274,9 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname) fd = open(ttyname, O_RDWR|O_NOCTTY); if (fd != -1) { - mysignal(SIGHUP, SIG_IGN); + signal(SIGHUP, SIG_IGN); ioctl(fd, TCVHUP, (char *)NULL); - mysignal(SIGHUP, SIG_DFL); + signal(SIGHUP, SIG_DFL); setpgid(0, 0); close(fd); } else { @@ -323,9 +323,9 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname) error("SETPGRP %s",strerror(errno)); #endif /* HAVE_NEWS4 */ #ifdef USE_VHANGUP - old = mysignal(SIGHUP, SIG_IGN); + old = signal(SIGHUP, SIG_IGN); vhangup(); - mysignal(SIGHUP, old); + signal(SIGHUP, old); #endif /* USE_VHANGUP */ fd = open(ttyname, O_RDWR); if (fd < 0) { -- cgit v1.2.3 From a05ec477b32c50aa793d865a231a3ec9d0ab1234 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Tue, 23 Sep 2003 18:59:08 +1000 Subject: - markus@cvs.openbsd.org 2003/09/18 08:49:45 [deattack.c misc.c session.c ssh-agent.c] more buffer allocation fixes; from Solar Designer; CAN-2003-0682; ok millert@ --- ChangeLog | 6 +++++- deattack.c | 6 +++--- misc.c | 13 ++++++++----- session.c | 18 ++++++++++-------- ssh-agent.c | 17 +++++++++-------- 5 files changed, 35 insertions(+), 25 deletions(-) (limited to 'misc.c') diff --git a/ChangeLog b/ChangeLog index 0a73b9948..fd254c761 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ - markus@cvs.openbsd.org 2003/09/18 07:54:48 [buffer.c] protect against double free; #660; zardoz at users.sf.net + - markus@cvs.openbsd.org 2003/09/18 08:49:45 + [deattack.c misc.c session.c ssh-agent.c] + more buffer allocation fixes; from Solar Designer; CAN-2003-0682; + ok millert@ 20030922 - (dtucker) [Makefile.in] Bug #644: Fix "make clean" for out-of-tree @@ -1171,4 +1175,4 @@ - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo. Report from murple@murple.net, diagnosis from dtucker@zip.com.au -$Id: ChangeLog,v 1.2994.2.29 2003/09/23 08:55:43 dtucker Exp $ +$Id: ChangeLog,v 1.2994.2.30 2003/09/23 08:59:08 dtucker Exp $ diff --git a/deattack.c b/deattack.c index 0442501e7..8b55d6686 100644 --- a/deattack.c +++ b/deattack.c @@ -18,7 +18,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: deattack.c,v 1.18 2002/03/04 17:27:39 stevesk Exp $"); +RCSID("$OpenBSD: deattack.c,v 1.19 2003/09/18 08:49:45 markus Exp $"); #include "deattack.h" #include "log.h" @@ -100,12 +100,12 @@ detect_attack(u_char *buf, u_int32_t len, u_char *IV) if (h == NULL) { debug("Installing crc compensation attack detector."); + h = (u_int16_t *) xmalloc(l * HASH_ENTRYSIZE); n = l; - h = (u_int16_t *) xmalloc(n * HASH_ENTRYSIZE); } else { if (l > n) { + h = (u_int16_t *) xrealloc(h, l * HASH_ENTRYSIZE); n = l; - h = (u_int16_t *) xrealloc(h, n * HASH_ENTRYSIZE); } } diff --git a/misc.c b/misc.c index c457a952c..ac616de02 100644 --- a/misc.c +++ b/misc.c @@ -23,7 +23,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: misc.c,v 1.21 2003/04/12 10:15:36 markus Exp $"); +RCSID("$OpenBSD: misc.c,v 1.22 2003/09/18 08:49:45 markus Exp $"); #include "misc.h" #include "log.h" @@ -308,18 +308,21 @@ addargs(arglist *args, char *fmt, ...) { va_list ap; char buf[1024]; + int nalloc; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); + nalloc = args->nalloc; if (args->list == NULL) { - args->nalloc = 32; + nalloc = 32; args->num = 0; - } else if (args->num+2 >= args->nalloc) - args->nalloc *= 2; + } else if (args->num+2 >= nalloc) + nalloc *= 2; - args->list = xrealloc(args->list, args->nalloc * sizeof(char *)); + args->list = xrealloc(args->list, nalloc * sizeof(char *)); + args->nalloc = nalloc; args->list[args->num++] = xstrdup(buf); args->list[args->num] = NULL; } diff --git a/session.c b/session.c index 616fee971..2898ac518 100644 --- a/session.c +++ b/session.c @@ -33,7 +33,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: session.c,v 1.163 2003/08/31 13:29:05 markus Exp $"); +RCSID("$OpenBSD: session.c,v 1.164 2003/09/18 08:49:45 markus Exp $"); #include "ssh.h" #include "ssh1.h" @@ -798,8 +798,9 @@ void child_set_env(char ***envp, u_int *envsizep, const char *name, const char *value) { - u_int i, namelen; char **env; + u_int envsize; + u_int i, namelen; /* * If we're passed an uninitialized list, allocate a single null @@ -826,12 +827,13 @@ child_set_env(char ***envp, u_int *envsizep, const char *name, xfree(env[i]); } else { /* New variable. Expand if necessary. */ - if (i >= (*envsizep) - 1) { - if (*envsizep >= 1000) - fatal("child_set_env: too many env vars," - " skipping: %.100s", name); - (*envsizep) += 50; - env = (*envp) = xrealloc(env, (*envsizep) * sizeof(char *)); + envsize = *envsizep; + if (i >= envsize - 1) { + if (envsize >= 1000) + fatal("child_set_env: too many env vars"); + envsize += 50; + env = (*envp) = xrealloc(env, envsize * sizeof(char *)); + *envsizep = envsize; } /* Need to set the NULL pointer at end of array beyond the new slot. */ env[i + 1] = NULL; diff --git a/ssh-agent.c b/ssh-agent.c index c05c61468..e1e6cae9b 100644 --- a/ssh-agent.c +++ b/ssh-agent.c @@ -35,7 +35,7 @@ #include "includes.h" #include "openbsd-compat/sys-queue.h" -RCSID("$OpenBSD: ssh-agent.c,v 1.111 2003/06/12 19:12:03 markus Exp $"); +RCSID("$OpenBSD: ssh-agent.c,v 1.112 2003/09/18 08:49:45 markus Exp $"); #include #include @@ -784,7 +784,7 @@ process_message(SocketEntry *e) static void new_socket(sock_type type, int fd) { - u_int i, old_alloc; + u_int i, old_alloc, new_alloc; if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) error("fcntl O_NONBLOCK: %s", strerror(errno)); @@ -795,25 +795,26 @@ new_socket(sock_type type, int fd) for (i = 0; i < sockets_alloc; i++) if (sockets[i].type == AUTH_UNUSED) { sockets[i].fd = fd; - sockets[i].type = type; buffer_init(&sockets[i].input); buffer_init(&sockets[i].output); buffer_init(&sockets[i].request); + sockets[i].type = type; return; } old_alloc = sockets_alloc; - sockets_alloc += 10; + new_alloc = sockets_alloc + 10; if (sockets) - sockets = xrealloc(sockets, sockets_alloc * sizeof(sockets[0])); + sockets = xrealloc(sockets, new_alloc * sizeof(sockets[0])); else - sockets = xmalloc(sockets_alloc * sizeof(sockets[0])); - for (i = old_alloc; i < sockets_alloc; i++) + sockets = xmalloc(new_alloc * sizeof(sockets[0])); + for (i = old_alloc; i < new_alloc; i++) sockets[i].type = AUTH_UNUSED; - sockets[old_alloc].type = type; + sockets_alloc = new_alloc; sockets[old_alloc].fd = fd; buffer_init(&sockets[old_alloc].input); buffer_init(&sockets[old_alloc].output); buffer_init(&sockets[old_alloc].request); + sockets[old_alloc].type = type; } static int -- cgit v1.2.3