summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Carr <jfc@mit.edu>1991-12-20 08:29:33 +0000
committerJohn Carr <jfc@mit.edu>1991-12-20 08:29:33 +0000
commit1602258ec8599f5d15e18a5b00346b9947b46560 (patch)
tree61823cd9e95f322f0437ba2317eccde8b00e334a /src
parent971f569cd885457ff22e2df5fb7b2560375f8101 (diff)
downloadkrb5-1602258ec8599f5d15e18a5b00346b9947b46560.tar.gz
krb5-1602258ec8599f5d15e18a5b00346b9947b46560.tar.xz
krb5-1602258ec8599f5d15e18a5b00346b9947b46560.zip
Fixes from pato@apollo.com:
1. allow extra whitespace in file 2. fix comparison of realm names to avoid prefix matches 3. reduce calls to realloc() git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2197 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/lib/krb5/os/get_krbhst.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/lib/krb5/os/get_krbhst.c b/src/lib/krb5/os/get_krbhst.c
index 0e719506c..f42646740 100644
--- a/src/lib/krb5/os/get_krbhst.c
+++ b/src/lib/krb5/os/get_krbhst.c
@@ -33,6 +33,7 @@ static char rcsid_get_krbhst_c [] =
#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,10 +72,14 @@ char ***hostlist;
FILE *config_file;
char filebuf[BUFSIZ];
krb5_error_code retval;
- char *cp;
+ char *cp, *cp2;
register char **rethlist = 0;
- int hlsize = 1;
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,7 +102,24 @@ char ***hostlist;
retval = KRB5_CONFIG_BADFORMAT;
break;
}
- rethlist[hlindex] = strdup(&filebuf[realm->length+1]);
+
+ 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,13 +128,7 @@ char ***hostlist;
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;