Date: Wed, 17 Aug 2011 15:22:58 +0000 (UTC) From: Jaakko Heinonen <jh@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r224945 - stable/8/usr.bin/rs Message-ID: <201108171522.p7HFMwgj011065@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jh Date: Wed Aug 17 15:22:58 2011 New Revision: 224945 URL: http://svn.freebsd.org/changeset/base/224945 Log: MFC r218411: - Use LINE_MAX from limits.h as the maximum line length instead of BUFSIZ. Use LINE_MAX * 2 as the buffer size (BSIZE). - Error out if we encounter a line longer than LINE_MAX. The previous behavior was to silently split long lines and produce corrupted output. PR: bin/151384 Modified: stable/8/usr.bin/rs/rs.c Directory Properties: stable/8/usr.bin/rs/ (props changed) Modified: stable/8/usr.bin/rs/rs.c ============================================================================== --- stable/8/usr.bin/rs/rs.c Wed Aug 17 15:19:25 2011 (r224944) +++ stable/8/usr.bin/rs/rs.c Wed Aug 17 15:22:58 2011 (r224945) @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <ctype.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -332,8 +333,8 @@ prepfile(void) warnx("%d is colwidths, nelem %d", colwidths[i], nelem);*/ } -#define BSIZE 2048 -char ibuf[BSIZE]; /* two screenfuls should do */ +#define BSIZE (LINE_MAX * 2) +char ibuf[BSIZE]; int getline(void) /* get line; maintain curline, curlen; manage storage */ @@ -354,7 +355,7 @@ getline(void) /* get line; maintain curl curline = ibuf; } } - if (!putlength && endblock - curline < BUFSIZ) { /* need storage */ + if (!putlength && endblock - curline < LINE_MAX + 1) { /* need storage */ /*ww = endblock-curline; tt += ww;*/ /*printf("#wasted %d total %d\n",ww,tt);*/ if (!(curline = (char *) malloc(BSIZE))) @@ -362,11 +363,16 @@ getline(void) /* get line; maintain curl endblock = curline + BSIZE; /*printf("#endb %d curline %d\n",endblock,curline);*/ } - for (p = curline, i = 1; i < BUFSIZ; *p++ = c, i++) - if ((c = getchar()) == EOF || c == '\n') + for (p = curline, i = 0;; *p++ = c, i++) { + if ((c = getchar()) == EOF) break; + if (i >= LINE_MAX) + errx(1, "maximum line length (%d) exceeded", LINE_MAX); + if (c == '\n') + break; + } *p = '\0'; - curlen = i - 1; + curlen = i; return(c); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108171522.p7HFMwgj011065>