Patch to improve -p error message.

Mo DeJong mdejong at cygnus.com
Mon Jan 15 18:29:44 EST 2001


On Mon, 15 Jan 2001, Kevin Steves wrote:

> you can still enter -4501, which is invalid and not noted, or 4501L
> which will work but may not be what you wanted.  if you want to clean up
> atoi() handling you might sweep the tree (scp has -P till exempel) and
> see how head.c from openbsd uses strtol() in a paranoid fashion.
> 
> On Wed, 10 Jan 2001, Mo DeJong wrote:
> : I got sick of getting a lame error message when I typed
> : the wrong thing in for a -p argument, so I wrote
> : up this patch.


Well, how about something like this?

Index: ssh.c
===================================================================
RCS file: /cvs/openssh_cvs/ssh.c,v
retrieving revision 1.56
diff -u -r1.56 ssh.c
--- ssh.c       2000/12/28 16:40:05     1.56
+++ ssh.c       2001/01/15 07:27:37
@@ -229,7 +229,7 @@
 {
        int i, opt, optind, exit_status, ok;
        u_short fwd_port, fwd_host_port;
-       char *optarg, *cp, buf[256];
+       char *optarg, *cp, *tmp, buf[256];
        struct stat st;
        struct passwd *pw, pwcopy;
        int dummy;
@@ -436,6 +436,14 @@
                        }
                        break;
                case 'p':
+                       for (tmp = optarg; *tmp ; tmp++) {
+                           if (*tmp < '0' || *tmp > '9') {
+                                fprintf(stderr,
+                                    "Bad port specification '%s'.\n",
+                                        optarg);
+                                exit(1);
+                            }
+                        }
                        options.port = atoi(optarg);
                        break;
                case 'l':


Mo DeJong
Red Hat Inc





More information about the openssh-unix-dev mailing list