summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-09-12 17:56:15 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-09-12 17:56:15 +0000
commit1a1747172ec251739c846a378310bf7b5ba5b55d (patch)
treee3fcc9f557ab86cc6b6213e7b448885593661997 /ssh.c
parent19ceb17040ba3c93833d4219d83f2002d25fd3fa (diff)
- stevesk@cvs.openbsd.org 2001/08/29 23:27:23
[ssh.c] validate ports for -L/-R; ok markus@
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/ssh.c b/ssh.c
index 4fcaaeae5..d500e8493 100644
--- a/ssh.c
+++ b/ssh.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: ssh.c,v 1.140 2001/08/29 23:13:10 stevesk Exp $"); 42RCSID("$OpenBSD: ssh.c,v 1.141 2001/08/29 23:27:23 stevesk Exp $");
43 43
44#include <openssl/evp.h> 44#include <openssl/evp.h>
45#include <openssl/err.h> 45#include <openssl/err.h>
@@ -258,6 +258,7 @@ main(int ac, char **av)
258{ 258{
259 int i, opt, exit_status, cerr; 259 int i, opt, exit_status, cerr;
260 u_short fwd_port, fwd_host_port; 260 u_short fwd_port, fwd_host_port;
261 char sfwd_port[6], sfwd_host_port[6];
261 char *p, *cp, buf[256]; 262 char *p, *cp, buf[256];
262 struct stat st; 263 struct stat st;
263 struct passwd *pw; 264 struct passwd *pw;
@@ -470,33 +471,31 @@ again:
470 case 'l': 471 case 'l':
471 options.user = optarg; 472 options.user = optarg;
472 break; 473 break;
474
475 case 'L':
473 case 'R': 476 case 'R':
474 if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf, 477 if (sscanf(optarg, "%5[0-9]:%255[^:]:%5[0-9]",
475 &fwd_host_port) != 3 && 478 sfwd_port, buf, sfwd_host_port) != 3 &&
476 sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf, 479 sscanf(optarg, "%5[0-9]/%255[^/]/%5[0-9]",
477 &fwd_host_port) != 3) { 480 sfwd_port, buf, sfwd_host_port) != 3) {
478 fprintf(stderr, 481 fprintf(stderr,
479 "Bad forwarding specification '%s'.\n", 482 "Bad forwarding specification '%s'\n",
480 optarg); 483 optarg);
481 usage(); 484 usage();
482 /* NOTREACHED */ 485 /* NOTREACHED */
483 } 486 }
484 add_remote_forward(&options, fwd_port, buf, 487 if ((fwd_port = a2port(sfwd_port)) == 0 ||
485 fwd_host_port); 488 (fwd_host_port = a2port(sfwd_host_port)) == 0) {
486 break;
487 case 'L':
488 if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf,
489 &fwd_host_port) != 3 &&
490 sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf,
491 &fwd_host_port) != 3) {
492 fprintf(stderr, 489 fprintf(stderr,
493 "Bad forwarding specification '%s'.\n", 490 "Bad forwarding port(s) '%s'\n", optarg);
494 optarg); 491 exit(1);
495 usage();
496 /* NOTREACHED */
497 } 492 }
498 add_local_forward(&options, fwd_port, buf, 493 if (opt == 'L')
499 fwd_host_port); 494 add_local_forward(&options, fwd_port, buf,
495 fwd_host_port);
496 else if (opt == 'R')
497 add_remote_forward(&options, fwd_port, buf,
498 fwd_host_port);
500 break; 499 break;
501 500
502 case 'D': 501 case 'D':