diff options
author | 2007-09-19 11:53:27 +0000 | |
---|---|---|
committer | 2007-09-19 11:53:27 +0000 | |
commit | a10137310b2340f26ab3c634b03027ad5825eb17 (patch) | |
tree | c363e7cc56830d4241b6b76301ecd2c357233932 | |
parent | tidy up a little. (diff) | |
download | wireguard-openbsd-a10137310b2340f26ab3c634b03027ad5825eb17.tar.xz wireguard-openbsd-a10137310b2340f26ab3c634b03027ad5825eb17.zip |
Usage of fgetln() instead of fgets() in .cvsrc parsing handles line
numbers better and allows longer command arguments.
OK joris@
-rw-r--r-- | usr.bin/cvs/cvs.c | 28 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 10 |
2 files changed, 20 insertions, 18 deletions
diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c index 3c860bfa35d..af238f0974c 100644 --- a/usr.bin/cvs/cvs.c +++ b/usr.bin/cvs/cvs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.c,v 1.132 2007/09/10 10:29:12 tobias Exp $ */ +/* $OpenBSD: cvs.c,v 1.133 2007/09/19 11:53:27 tobias Exp $ */ /* * Copyright (c) 2006, 2007 Joris Vink <joris@openbsd.org> * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> @@ -394,7 +394,7 @@ cvs_getopt(int argc, char **argv) static void cvs_read_rcfile(void) { - char rcpath[MAXPATHLEN], linebuf[128], *lp, *p; + char rcpath[MAXPATHLEN], *buf, *lbuf, *lp, *p; int i, linenum; size_t len; struct cvs_cmd *cmdp; @@ -416,19 +416,21 @@ cvs_read_rcfile(void) return; } - while (fgets(linebuf, (int)sizeof(linebuf), fp) != NULL) { - linenum++; - if ((len = strlen(linebuf)) == 0) - continue; - if (linebuf[len - 1] != '\n') { - cvs_log(LP_ERR, "line too long in `%s:%d'", rcpath, - linenum); - break; + lbuf = NULL; + while ((buf = fgetln(fp, &len)) != NULL) { + if (buf[len - 1] == '\n') { + buf[len - 1] = '\0'; + } else { + lbuf = xmalloc(len + 1); + memcpy(lbuf, buf, len); + lbuf[len] = '\0'; + buf = lbuf; } - linebuf[--len] = '\0'; + + linenum++; /* skip any whitespaces */ - p = linebuf; + p = buf; while (*p == ' ') p++; @@ -462,6 +464,8 @@ cvs_read_rcfile(void) cmdp->cmd_defargs = xstrdup(lp); } } + if (lbuf != NULL) + xfree(lbuf); if (ferror(fp)) { cvs_log(LP_NOTICE, "failed to read line from `%s'", rcpath); diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 7d4472ea838..2a8206d8a21 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.116 2007/09/09 20:24:06 tobias Exp $ */ +/* $OpenBSD: util.c,v 1.117 2007/09/19 11:53:27 tobias Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -226,14 +226,11 @@ cvs_cksum(const char *file, char *dst, size_t len) int cvs_getargv(const char *line, char **argv, int argvlen) { - size_t l; u_int i; int argc, error; - char linebuf[256], qbuf[128], *lp, *cp, *arg; + char qbuf[128], *linebuf, *lp, *cp, *arg; - l = strlcpy(linebuf, line, sizeof(linebuf)); - if (l >= sizeof(linebuf)) - fatal("cvs_getargv: string truncation"); + linebuf = xstrdup(line); memset(argv, 0, argvlen * sizeof(char *)); argc = 0; @@ -292,6 +289,7 @@ cvs_getargv(const char *line, char **argv, int argvlen) argc = -1; } + xfree(linebuf); return (argc); } |