From 6e44366e4f62aeac5ff2384dce1c1c75b24c6952 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 21 Nov 2006 00:56:56 +0000 Subject: [PATCH] DEVEL15-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. (cherry picked from commit 769f4e49b60b15b27eb2898a5b28c2d99fc0238c) --- 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 338d644..8003896 100644 --- a/src/auth/cellconfig.c +++ b/src/auth/cellconfig.c @@ -478,7 +478,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); @@ -488,12 +488,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; } -- 1.9.4