diff options
author | Kevin Steves <stevesk@cvs.openbsd.org> | 2001-08-29 23:27:24 +0000 |
---|---|---|
committer | Kevin Steves <stevesk@cvs.openbsd.org> | 2001-08-29 23:27:24 +0000 |
commit | 1a8a60ad4d599c1efc611788a715591d8dcce3db (patch) | |
tree | c706e37641bd71073c0832da6e066d3bc8d7c929 | |
parent | 132e0cb3c40d761ffd43be13f68a4d4317e1b6bc (diff) |
validate ports for -L/-R; ok markus@
-rw-r--r-- | usr.bin/ssh/ssh.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c index dadd0403ef4..127d3be5e10 100644 --- a/usr.bin/ssh/ssh.c +++ b/usr.bin/ssh/ssh.c @@ -39,7 +39,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh.c,v 1.140 2001/08/29 23:13:10 stevesk Exp $"); +RCSID("$OpenBSD: ssh.c,v 1.141 2001/08/29 23:27:23 stevesk Exp $"); #include <openssl/evp.h> #include <openssl/err.h> @@ -250,6 +250,7 @@ main(int ac, char **av) { int i, opt, exit_status, cerr; u_short fwd_port, fwd_host_port; + char sfwd_port[6], sfwd_host_port[6]; char *p, *cp, buf[256]; struct stat st; struct passwd *pw; @@ -453,33 +454,31 @@ again: case 'l': options.user = optarg; break; + + case 'L': case 'R': - if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf, - &fwd_host_port) != 3 && - sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf, - &fwd_host_port) != 3) { + if (sscanf(optarg, "%5[0-9]:%255[^:]:%5[0-9]", + sfwd_port, buf, sfwd_host_port) != 3 && + sscanf(optarg, "%5[0-9]/%255[^/]/%5[0-9]", + sfwd_port, buf, sfwd_host_port) != 3) { fprintf(stderr, - "Bad forwarding specification '%s'.\n", + "Bad forwarding specification '%s'\n", optarg); usage(); /* NOTREACHED */ } - add_remote_forward(&options, fwd_port, buf, - fwd_host_port); - break; - case 'L': - if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf, - &fwd_host_port) != 3 && - sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf, - &fwd_host_port) != 3) { + if ((fwd_port = a2port(sfwd_port)) == 0 || + (fwd_host_port = a2port(sfwd_host_port)) == 0) { fprintf(stderr, - "Bad forwarding specification '%s'.\n", - optarg); - usage(); - /* NOTREACHED */ + "Bad forwarding port(s) '%s'\n", optarg); + exit(1); } - add_local_forward(&options, fwd_port, buf, - fwd_host_port); + if (opt == 'L') + add_local_forward(&options, fwd_port, buf, + fwd_host_port); + else if (opt == 'R') + add_remote_forward(&options, fwd_port, buf, + fwd_host_port); break; case 'D': |