[200] in Kerberos-V5-bugs

home help back first fref pref prev next nref lref last post

fixes to get_krbhst.c

daemon@ATHENA.MIT.EDU (Joe Pato)
Thu Sep 19 09:25:58 1991

From: pato@apollo.com (Joe Pato)
Date: Thu, 19 Sep 91 09:22:12 EDT
To: krb5-bugs@MIT.EDU
Cc: sommerfeld@apollo.com

Fixes for bugs in get_krbhst.c:
    1) Allow any amount of whitespace between tokens
    2) Fix comparison of realm names (to avoid prefix matches)
    3) Avoid realloc for common case (set default hlsize to 2)

                    -- Joe Pato
                       Cooperative Object Computing Division / East
                       Hewlett-Packard Company
                       pato@apollo.hp.com


(munin|26): diff -c /prgy/krb5/lib/os/get_krbhst.c/MIT-beta1{,/krb_config_parse}
*** /prgy/krb5/lib/os/get_krbhst.c/MIT-beta1	Thu Jun  6 09:48:09 1991
--- /prgy/krb5/lib/os/get_krbhst.c/MIT-beta1/krb_config_parse	Wed Sep 18 15:00:29 1991
***************
*** 33,38 ****
--- 33,39 ----
  #include <krb5/krb5.h>
  #include <krb5/ext-proto.h>
  #include <stdio.h>
+ #include <ctype.h>
  
  /*
   Figures out the Kerberos server names for the given realm, filling in a
***************
*** 71,80 ****
      FILE *config_file;
      char filebuf[BUFSIZ];
      krb5_error_code retval;
!     char *cp;
      register char **rethlist = 0;
-     int hlsize = 1;
      int hlindex = 0;
  
      if (!(config_file = fopen(krb5_config_file, "r")))
  	/* can't open */
--- 72,85 ----
      FILE *config_file;
      char filebuf[BUFSIZ];
      krb5_error_code retval;
!     char *cp, *cp2;
      register char **rethlist = 0;
      int hlindex = 0;
+     int hlsize = 2;                     /* Always have to null terminate
+                                          * host list, so be sure there
+                                          * is enough room in the common
+                                          * case.
+                                          */
  
      if (!(config_file = fopen(krb5_config_file, "r")))
  	/* can't open */
***************
*** 97,103 ****
  		retval = KRB5_CONFIG_BADFORMAT;
  		break;
  	    }
! 	    rethlist[hlindex] = strdup(&filebuf[realm->length+1]);
  	    if (!rethlist[hlindex]) {
  		for (--hlindex; hlindex >= 0; hlindex--)
  		    free(rethlist[hlindex]);
--- 102,125 ----
  		retval = KRB5_CONFIG_BADFORMAT;
  		break;
  	    }
! 
!             if (!isspace(filebuf[realm->length])) {
!                 continue;               /* no match */
!             }
! 
!             /* Throw away any whitespace between tokens */
!             for (cp = &filebuf[realm->length + 1]; isspace(*cp); cp++);
!             if (! *cp) {
! 		/* no hostname on config line */
! 		retval = KRB5_CONFIG_BADFORMAT;
! 		break;
! 	    }
! 
!             /* Throw away any trailing whitespace or tokens */
!             for (cp2 = cp+1; *cp2 && !isspace(*cp2); cp2++);
!             *cp2 = '\0';
! 
! 	    rethlist[hlindex] = strdup(cp);
  	    if (!rethlist[hlindex]) {
  		for (--hlindex; hlindex >= 0; hlindex--)
  		    free(rethlist[hlindex]);
***************
*** 106,118 ****
  		retval = ENOMEM;
  		break;
  	    }
! 	    /* chop off remainder of line */
! 	    if (cp = strchr(rethlist[hlindex], ' '))
! 		*cp = '\0';
! 	    if (cp = strchr(rethlist[hlindex], '\t'))
! 		*cp = '\0';
! 	    if (cp = strchr(rethlist[hlindex], '\n'))
! 		*cp = '\0';
  	    if (++hlindex >= hlsize) {
  		/* need larger pointer array */
  		hlsize *= 2;
--- 128,134 ----
  		retval = ENOMEM;
  		break;
  	    }
! 
  	    if (++hlindex >= hlsize) {
  		/* need larger pointer array */
  		hlsize *= 2;
-------

home help back first fref pref prev next nref lref last post