Browse Source

[daemons] Sanity check port number arguments before use

2008-05-29 Martin Nagy <mnagy@redhat.com>

	* */*main.c: Sanity check port numbers before using.
Paul Jakma 14 years ago
parent
commit
0d6b2ee249
7 changed files with 22 additions and 7 deletions
  1. 4 0
      ChangeLog
  2. 8 2
      bgpd/bgp_main.c
  3. 2 1
      ospf6d/ospf6_main.c
  4. 2 1
      ospfd/ospf_main.c
  5. 2 1
      ripd/rip_main.c
  6. 2 1
      ripngd/ripng_main.c
  7. 2 1
      zebra/main.c

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+2008-05-29 Martin Nagy <mnagy@redhat.com>
+
+	* */*main.c: Sanity check port numbers before using.
+
 2008-01-30 Peter Szilagyi <sp615@hszk.bme.hu>
 
 	* lib/stream.h: Remove named 'new' parameter in prototype

+ 8 - 2
bgpd/bgp_main.c

@@ -203,6 +203,7 @@ main (int argc, char **argv)
   int dryrun = 0;
   char *progname;
   struct thread thread;
+  int tmp_port;
 
   /* Set umask before anything for security */
   umask (0027);
@@ -238,7 +239,11 @@ main (int argc, char **argv)
           pid_file = optarg;
           break;
 	case 'p':
-	  bm->port = atoi (optarg);
+	  tmp_port = atoi (optarg);
+	  if (tmp_port <= 0 || tmp_port > 0xffff)
+	    bm->port = BGP_PORT_DEFAULT;
+	  else
+	    bm->port = tmp_port;
 	  break;
 	case 'A':
 	  vty_addr = optarg;
@@ -252,7 +257,8 @@ main (int argc, char **argv)
               break;
             } 
           vty_port = atoi (optarg);
-          vty_port = (vty_port ? vty_port : BGP_VTY_PORT);
+	  if (vty_port <= 0 || vty_port > 0xffff)
+	    vty_port = BGP_VTY_PORT;
 	  break;
 	case 'r':
 	  retain_mode = 1;

+ 2 - 1
ospf6d/ospf6_main.c

@@ -227,7 +227,8 @@ main (int argc, char *argv[], char *envp[])
               break;
             }
           vty_port = atoi (optarg);
-          vty_port = (vty_port ? vty_port : OSPF6_VTY_PORT);
+          if (vty_port <= 0 || vty_port > 0xffff)
+            vty_port = OSPF6_VTY_PORT;
           break;
         case 'u':
           ospf6d_privs.user = optarg;

+ 2 - 1
ospfd/ospf_main.c

@@ -245,7 +245,8 @@ main (int argc, char **argv)
               break;
             } 
           vty_port = atoi (optarg);
-          vty_port = (vty_port ? vty_port : OSPF_VTY_PORT);
+          if (vty_port <= 0 || vty_port > 0xffff)
+            vty_port = OSPF_VTY_PORT;
   	  break;
 	case 'u':
 	  ospfd_privs.user = optarg;

+ 2 - 1
ripd/rip_main.c

@@ -236,7 +236,8 @@ main (int argc, char **argv)
               break;
             } 
           vty_port = atoi (optarg);
-          vty_port = (vty_port ? vty_port : RIP_VTY_PORT);
+          if (vty_port <= 0 || vty_port > 0xffff)
+            vty_port = RIP_VTY_PORT;
 	  break;
 	case 'r':
 	  retain_mode = 1;

+ 2 - 1
ripngd/ripng_main.c

@@ -240,7 +240,8 @@ main (int argc, char **argv)
               break;
             } 
           vty_port = atoi (optarg);
-          vty_port = (vty_port ? vty_port : RIPNG_VTY_PORT);
+          if (vty_port <= 0 || vty_port > 0xffff)
+            vty_port = RIPNG_VTY_PORT;
           break;
 	case 'r':
 	  retain_mode = 1;

+ 2 - 1
zebra/main.c

@@ -275,7 +275,8 @@ main (int argc, char **argv)
 	      break;
 	    } 
 	  vty_port = atoi (optarg);
-	  vty_port = (vty_port ? vty_port : ZEBRA_VTY_PORT);
+	  if (vty_port <= 0 || vty_port > 0xffff)
+	    vty_port = ZEBRA_VTY_PORT;
 	  break;
 	case 'r':
 	  retain_mode = 1;