diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2004-07-27 16:35:49 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2004-07-27 16:35:49 +0000 |
commit | 520e5cc1bbe135f17cfcfa7bc6f48d740a0efc72 (patch) | |
tree | fada06e0f5f58b3c50a0cc5ea36aeaa46aa105b8 /usr.bin/cvs/root.c | |
parent | 969ead97091953e57eacaf9f57695283bd4cacff (diff) |
Be less retarded when parsing the contents of a CVS/Root file
Diffstat (limited to 'usr.bin/cvs/root.c')
-rw-r--r-- | usr.bin/cvs/root.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/usr.bin/cvs/root.c b/usr.bin/cvs/root.c index 73611b96f69..f192c3af28c 100644 --- a/usr.bin/cvs/root.c +++ b/usr.bin/cvs/root.c @@ -1,4 +1,4 @@ -/* $OpenBSD: root.c,v 1.4 2004/07/27 12:18:02 jfb Exp $ */ +/* $OpenBSD: root.c,v 1.5 2004/07/27 16:35:48 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -213,7 +213,7 @@ struct cvsroot* cvsroot_get(const char *dir) { size_t len; - char rootpath[MAXPATHLEN], *rootstr, *line; + char rootpath[MAXPATHLEN], *rootstr, line[128]; FILE *fp; struct cvsroot *rp; @@ -236,28 +236,19 @@ cvsroot_get(const char *dir) } } - line = fgetln(fp, &len); - if (line == NULL) { + if (fgets(line, sizeof(line), fp) == NULL) { cvs_log(LP_ERR, "failed to read CVSROOT line from CVS/Root"); (void)fclose(fp); - } - - /* line is not NUL-terminated, but we don't need to allocate an - * extra byte because we don't want the trailing newline. It will - * get replaced by a \0. - */ - rootstr = (char *)malloc(len); - if (rootstr == NULL) { - cvs_log(LP_ERRNO, "failed to allocate CVSROOT string"); - (void)fclose(fp); return (NULL); } - memcpy(rootstr, line, len - 1); - rootstr[len - 1] = '\0'; - rp = cvsroot_parse(rootstr); - (void)fclose(fp); - free(rootstr); - return (rp); + len = strlen(line); + if (len == 0) { + cvs_log(LP_WARN, "empty CVS/Root file"); + } + else if (line[len - 1] == '\n') + line[--len] = '\0'; + + return cvsroot_parse(line); } |