mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-31 01:35:11 +02:00
- stevesk@cvs.openbsd.org 2001/04/12 20:09:38
[misc.c misc.h readconf.c servconf.c ssh.c sshd.c] robust port validation; ok markus@ jakob@
This commit is contained in:
parent
d69dab3cde
commit
19066a112b
@ -16,6 +16,9 @@
|
|||||||
- markus@cvs.openbsd.org 2001/04/12 19:39:27
|
- markus@cvs.openbsd.org 2001/04/12 19:39:27
|
||||||
[readconf.c]
|
[readconf.c]
|
||||||
typo
|
typo
|
||||||
|
- stevesk@cvs.openbsd.org 2001/04/12 20:09:38
|
||||||
|
[misc.c misc.h readconf.c servconf.c ssh.c sshd.c]
|
||||||
|
robust port validation; ok markus@ jakob@
|
||||||
- (bal) Added openbsd-compat/inet_ntop.[ch] since HP/UX (and others)
|
- (bal) Added openbsd-compat/inet_ntop.[ch] since HP/UX (and others)
|
||||||
lack it.
|
lack it.
|
||||||
|
|
||||||
@ -5038,4 +5041,4 @@
|
|||||||
- Wrote replacements for strlcpy and mkdtemp
|
- Wrote replacements for strlcpy and mkdtemp
|
||||||
- Released 1.0pre1
|
- Released 1.0pre1
|
||||||
|
|
||||||
$Id: ChangeLog,v 1.1104 2001/04/12 23:36:05 mouring Exp $
|
$Id: ChangeLog,v 1.1105 2001/04/12 23:39:26 mouring Exp $
|
||||||
|
19
misc.c
19
misc.c
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: misc.c,v 1.4 2001/02/28 17:52:54 deraadt Exp $ */
|
/* $OpenBSD: misc.c,v 1.5 2001/04/12 20:09:37 stevesk Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000 Markus Friedl. All rights reserved.
|
* Copyright (c) 2000 Markus Friedl. All rights reserved.
|
||||||
@ -25,7 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
RCSID("$OpenBSD: misc.c,v 1.4 2001/02/28 17:52:54 deraadt Exp $");
|
RCSID("$OpenBSD: misc.c,v 1.5 2001/04/12 20:09:37 stevesk Exp $");
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@ -116,6 +116,21 @@ pwcopy(struct passwd *pw)
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int a2port(const char *s)
|
||||||
|
{
|
||||||
|
long port;
|
||||||
|
char *endp;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
port = strtol(s, &endp, 0);
|
||||||
|
if (s == endp || *endp != '\0' ||
|
||||||
|
(errno == ERANGE && (port == LONG_MIN || port == LONG_MAX)) ||
|
||||||
|
port <= 0 || port > 65535)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
mysig_t
|
mysig_t
|
||||||
mysignal(int sig, mysig_t act)
|
mysignal(int sig, mysig_t act)
|
||||||
{
|
{
|
||||||
|
9
misc.h
9
misc.h
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: misc.h,v 1.3 2001/02/22 21:59:44 markus Exp $ */
|
/* $OpenBSD: misc.h,v 1.4 2001/04/12 20:09:36 stevesk Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||||
@ -22,6 +22,13 @@ void set_nonblock(int fd);
|
|||||||
|
|
||||||
struct passwd * pwcopy(struct passwd *pw);
|
struct passwd * pwcopy(struct passwd *pw);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert ASCII string to TCP/IP port number.
|
||||||
|
* Port must be >0 and <=65535.
|
||||||
|
* Return 0 if invalid.
|
||||||
|
*/
|
||||||
|
int a2port(const char *s);
|
||||||
|
|
||||||
/* wrapper for signal interface */
|
/* wrapper for signal interface */
|
||||||
typedef void (*mysig_t)(int);
|
typedef void (*mysig_t)(int);
|
||||||
mysig_t mysignal(int sig, mysig_t act);
|
mysig_t mysignal(int sig, mysig_t act);
|
||||||
|
14
readconf.c
14
readconf.c
@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
RCSID("$OpenBSD: readconf.c,v 1.73 2001/04/12 19:39:27 markus Exp $");
|
RCSID("$OpenBSD: readconf.c,v 1.74 2001/04/12 20:09:37 stevesk Exp $");
|
||||||
|
|
||||||
#include "ssh.h"
|
#include "ssh.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
@ -555,10 +555,10 @@ parse_int:
|
|||||||
arg = strdelim(&s);
|
arg = strdelim(&s);
|
||||||
if (!arg || *arg == '\0')
|
if (!arg || *arg == '\0')
|
||||||
fatal("%.200s line %d: Missing argument.", filename, linenum);
|
fatal("%.200s line %d: Missing argument.", filename, linenum);
|
||||||
if (arg[0] < '0' || arg[0] > '9')
|
fwd_port = a2port(arg);
|
||||||
|
if (fwd_port == 0)
|
||||||
fatal("%.200s line %d: Badly formatted port number.",
|
fatal("%.200s line %d: Badly formatted port number.",
|
||||||
filename, linenum);
|
filename, linenum);
|
||||||
fwd_port = atoi(arg);
|
|
||||||
arg = strdelim(&s);
|
arg = strdelim(&s);
|
||||||
if (!arg || *arg == '\0')
|
if (!arg || *arg == '\0')
|
||||||
fatal("%.200s line %d: Missing second argument.",
|
fatal("%.200s line %d: Missing second argument.",
|
||||||
@ -574,10 +574,10 @@ parse_int:
|
|||||||
arg = strdelim(&s);
|
arg = strdelim(&s);
|
||||||
if (!arg || *arg == '\0')
|
if (!arg || *arg == '\0')
|
||||||
fatal("%.200s line %d: Missing argument.", filename, linenum);
|
fatal("%.200s line %d: Missing argument.", filename, linenum);
|
||||||
if (arg[0] < '0' || arg[0] > '9')
|
fwd_port = a2port(arg);
|
||||||
|
if (fwd_port == 0)
|
||||||
fatal("%.200s line %d: Badly formatted port number.",
|
fatal("%.200s line %d: Badly formatted port number.",
|
||||||
filename, linenum);
|
filename, linenum);
|
||||||
fwd_port = atoi(arg);
|
|
||||||
arg = strdelim(&s);
|
arg = strdelim(&s);
|
||||||
if (!arg || *arg == '\0')
|
if (!arg || *arg == '\0')
|
||||||
fatal("%.200s line %d: Missing second argument.",
|
fatal("%.200s line %d: Missing second argument.",
|
||||||
@ -594,10 +594,10 @@ parse_int:
|
|||||||
if (!arg || *arg == '\0')
|
if (!arg || *arg == '\0')
|
||||||
fatal("%.200s line %d: Missing port argument.",
|
fatal("%.200s line %d: Missing port argument.",
|
||||||
filename, linenum);
|
filename, linenum);
|
||||||
if (arg[0] < '0' || arg[0] > '9')
|
fwd_port = a2port(arg);
|
||||||
|
if (fwd_port == 0)
|
||||||
fatal("%.200s line %d: Badly formatted port number.",
|
fatal("%.200s line %d: Badly formatted port number.",
|
||||||
filename, linenum);
|
filename, linenum);
|
||||||
fwd_port = atoi(arg);
|
|
||||||
add_local_forward(options, fwd_port, "socks4", 0);
|
add_local_forward(options, fwd_port, "socks4", 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
32
servconf.c
32
servconf.c
@ -10,7 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
RCSID("$OpenBSD: servconf.c,v 1.75 2001/04/12 19:15:25 markus Exp $");
|
RCSID("$OpenBSD: servconf.c,v 1.76 2001/04/12 20:09:37 stevesk Exp $");
|
||||||
|
|
||||||
#ifdef KRB4
|
#ifdef KRB4
|
||||||
#include <krb.h>
|
#include <krb.h>
|
||||||
@ -31,8 +31,7 @@ RCSID("$OpenBSD: servconf.c,v 1.75 2001/04/12 19:15:25 markus Exp $");
|
|||||||
#include "kex.h"
|
#include "kex.h"
|
||||||
#include "mac.h"
|
#include "mac.h"
|
||||||
|
|
||||||
/* add listen address */
|
void add_listen_addr(ServerOptions *options, char *addr, u_short port);
|
||||||
void add_listen_addr(ServerOptions *options, char *addr, char *port);
|
|
||||||
void add_one_listen_addr(ServerOptions *options, char *addr, u_short port);
|
void add_one_listen_addr(ServerOptions *options, char *addr, u_short port);
|
||||||
|
|
||||||
/* AF_UNSPEC or AF_INET or AF_INET6 */
|
/* AF_UNSPEC or AF_INET or AF_INET6 */
|
||||||
@ -117,7 +116,7 @@ fill_default_server_options(ServerOptions *options)
|
|||||||
if (options->num_ports == 0)
|
if (options->num_ports == 0)
|
||||||
options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
|
options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
|
||||||
if (options->listen_addrs == NULL)
|
if (options->listen_addrs == NULL)
|
||||||
add_listen_addr(options, NULL, NULL);
|
add_listen_addr(options, NULL, 0);
|
||||||
if (options->pid_file == NULL)
|
if (options->pid_file == NULL)
|
||||||
options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
|
options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
|
||||||
if (options->server_key_bits == -1)
|
if (options->server_key_bits == -1)
|
||||||
@ -312,21 +311,18 @@ parse_token(const char *cp, const char *filename,
|
|||||||
return sBadOption;
|
return sBadOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* add listen address
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
add_listen_addr(ServerOptions *options, char *addr, char *port)
|
add_listen_addr(ServerOptions *options, char *addr, u_short port)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (options->num_ports == 0)
|
if (options->num_ports == 0)
|
||||||
options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
|
options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
|
||||||
if (port == NULL)
|
if (port == 0)
|
||||||
for (i = 0; i < options->num_ports; i++)
|
for (i = 0; i < options->num_ports; i++)
|
||||||
add_one_listen_addr(options, addr, options->ports[i]);
|
add_one_listen_addr(options, addr, options->ports[i]);
|
||||||
else
|
else
|
||||||
add_one_listen_addr(options, addr, atoi(port));
|
add_one_listen_addr(options, addr, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -400,7 +396,10 @@ read_server_config(ServerOptions *options, const char *filename)
|
|||||||
if (!arg || *arg == '\0')
|
if (!arg || *arg == '\0')
|
||||||
fatal("%s line %d: missing port number.",
|
fatal("%s line %d: missing port number.",
|
||||||
filename, linenum);
|
filename, linenum);
|
||||||
options->ports[options->num_ports++] = atoi(arg);
|
options->ports[options->num_ports++] = a2port(arg);
|
||||||
|
if (options->ports[options->num_ports-1] == 0)
|
||||||
|
fatal("%s line %d: Badly formatted port number.",
|
||||||
|
filename, linenum);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sServerKeyBits:
|
case sServerKeyBits:
|
||||||
@ -438,20 +437,25 @@ parse_int:
|
|||||||
memmove(p, p+1, strlen(p+1)+1);
|
memmove(p, p+1, strlen(p+1)+1);
|
||||||
} else if (((p = strchr(arg, ':')) == NULL) ||
|
} else if (((p = strchr(arg, ':')) == NULL) ||
|
||||||
(strchr(p+1, ':') != NULL)) {
|
(strchr(p+1, ':') != NULL)) {
|
||||||
add_listen_addr(options, arg, NULL);
|
add_listen_addr(options, arg, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*p == ':') {
|
if (*p == ':') {
|
||||||
|
u_short port;
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
if (*p == '\0')
|
if (*p == '\0')
|
||||||
fatal("%s line %d: bad inet addr:port usage.",
|
fatal("%s line %d: bad inet addr:port usage.",
|
||||||
filename, linenum);
|
filename, linenum);
|
||||||
else {
|
else {
|
||||||
*(p-1) = '\0';
|
*(p-1) = '\0';
|
||||||
add_listen_addr(options, arg, p);
|
if ((port = a2port(p)) == 0)
|
||||||
|
fatal("%s line %d: bad port number.",
|
||||||
|
filename, linenum);
|
||||||
|
add_listen_addr(options, arg, port);
|
||||||
}
|
}
|
||||||
} else if (*p == '\0')
|
} else if (*p == '\0')
|
||||||
add_listen_addr(options, arg, NULL);
|
add_listen_addr(options, arg, 0);
|
||||||
else
|
else
|
||||||
fatal("%s line %d: bad inet addr usage.",
|
fatal("%s line %d: bad inet addr usage.",
|
||||||
filename, linenum);
|
filename, linenum);
|
||||||
|
14
ssh.c
14
ssh.c
@ -39,7 +39,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
RCSID("$OpenBSD: ssh.c,v 1.112 2001/04/12 19:15:25 markus Exp $");
|
RCSID("$OpenBSD: ssh.c,v 1.113 2001/04/12 20:09:37 stevesk Exp $");
|
||||||
|
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
@ -247,7 +247,7 @@ main(int ac, char **av)
|
|||||||
{
|
{
|
||||||
int i, opt, optind, exit_status, ok;
|
int i, opt, optind, exit_status, ok;
|
||||||
u_short fwd_port, fwd_host_port;
|
u_short fwd_port, fwd_host_port;
|
||||||
char *optarg, *cp, *endofnumber, buf[256];
|
char *optarg, *cp, buf[256];
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
int dummy;
|
int dummy;
|
||||||
@ -460,8 +460,8 @@ main(int ac, char **av)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
options.port = strtol(optarg, &endofnumber, 0);
|
options.port = a2port(optarg);
|
||||||
if (optarg == endofnumber) {
|
if (options.port == 0) {
|
||||||
fprintf(stderr, "Bad port '%s'\n", optarg);
|
fprintf(stderr, "Bad port '%s'\n", optarg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -493,9 +493,9 @@ main(int ac, char **av)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
fwd_port = strtol(optarg, &endofnumber, 0);
|
fwd_port = a2port(optarg);
|
||||||
if (optarg == endofnumber) {
|
if (fwd_port == 0) {
|
||||||
fprintf(stderr, "Bad port '%s'\n", optarg);
|
fprintf(stderr, "Bad dynamic port '%s'\n", optarg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
add_local_forward(&options, fwd_port, "socks4", 0);
|
add_local_forward(&options, fwd_port, "socks4", 0);
|
||||||
|
8
sshd.c
8
sshd.c
@ -40,7 +40,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
RCSID("$OpenBSD: sshd.c,v 1.192 2001/04/11 16:25:30 lebel Exp $");
|
RCSID("$OpenBSD: sshd.c,v 1.193 2001/04/12 20:09:38 stevesk Exp $");
|
||||||
|
|
||||||
#include <openssl/dh.h>
|
#include <openssl/dh.h>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
@ -611,7 +611,11 @@ main(int ac, char **av)
|
|||||||
fprintf(stderr, "too many ports.\n");
|
fprintf(stderr, "too many ports.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
options.ports[options.num_ports++] = atoi(optarg);
|
options.ports[options.num_ports++] = a2port(optarg);
|
||||||
|
if (options.ports[options.num_ports-1] == 0) {
|
||||||
|
fprintf(stderr, "Bad port number.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
options.login_grace_time = atoi(optarg);
|
options.login_grace_time = atoi(optarg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user