From 769f4e49b60b15b27eb2898a5b28c2d99fc0238c Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 21 Nov 2006 00:56:14 +0000 Subject: [PATCH] thiscell-whitespace-20061120 Be more liberal when parsing ThisCell. Accept and ignore leading and trailing whitespace and anything after the first whitespace character on the first line. Return an error for a read error or for an empty cell name. --- src/auth/cellconfig.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/auth/cellconfig.c b/src/auth/cellconfig.c index e08e4d07a..a5f8b3aa8 100644 --- a/src/auth/cellconfig.c +++ b/src/auth/cellconfig.c @@ -476,7 +476,7 @@ GetCellUnix(struct afsconf_dir *adir) { char *rc; char tbuffer[256]; - char *p; + char *start, *p; afsconf_FILE *fp; strcompose(tbuffer, 256, adir->name, "/", AFSDIR_THISCELL_FILE, NULL); @@ -486,12 +486,20 @@ GetCellUnix(struct afsconf_dir *adir) } rc = fgets(tbuffer, 256, fp); fclose(fp); - - p = strchr(tbuffer, '\n'); - if (p) - *p = '\0'; - - adir->cellName = strdup(tbuffer); + if (rc == NULL) + return -1; + + start = tbuffer; + while (*start != '\0' && isspace(*start)) + start++; + p = start; + while (*p != '\0' && !isspace(*p)) + p++; + *p = '\0'; + if (*start == '\0') + return -1; + + adir->cellName = strdup(start); return 0; } -- 2.39.5