summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2016-02-28 17:34:45 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2016-02-28 17:34:45 +0100
commit502d03d4f3047bdbe7f223354f851b28e16167fd (patch)
treeda15b564b9779418c850b10f345ed42cc2520d28
parent029bb88fc7244b2281b1a26b19d34c4e2ea12769 (diff)
null-terminate line at newline from getline()
-rw-r--r--sfeed_frames.c6
-rw-r--r--sfeed_html.c5
-rw-r--r--sfeed_mbox.c2
-rw-r--r--sfeed_plain.c6
4 files changed, 15 insertions, 4 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c
index 8674678..076e864 100644
--- a/sfeed_frames.c
+++ b/sfeed_frames.c
@@ -104,7 +104,7 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
{
char dirpath[PATH_MAX], filepath[PATH_MAX];
char *fields[FieldLast], *feedname, name[128];
- size_t namelen;
+ ssize_t linelen;
struct stat st;
FILE *fpcontent = NULL;
unsigned int isnew;
@@ -138,7 +138,9 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
}
fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", fpitems);
- while (getline(&line, &linesize, fpin) > 0) {
+ while ((linelen = getline(&line, &linesize, fpin)) > 0) {
+ if (line[linelen - 1] == '\n')
+ line[--linelen] = '\0';
if (!parseline(line, fields))
break;
/* write content */
diff --git a/sfeed_html.c b/sfeed_html.c
index dd8bdfd..028653b 100644
--- a/sfeed_html.c
+++ b/sfeed_html.c
@@ -19,6 +19,7 @@ printfeed(FILE *fp, struct feed *f)
char *fields[FieldLast];
time_t parsedtime;
unsigned int islink, isnew;
+ ssize_t linelen;
if (f->name[0] != '\0') {
fputs("<h2 id=\"", stdout);
@@ -31,7 +32,9 @@ printfeed(FILE *fp, struct feed *f)
}
fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", stdout);
- while (getline(&line, &linesize, fp) > 0) {
+ while ((linelen = getline(&line, &linesize, fp)) > 0) {
+ if (line[linelen - 1] == '\n')
+ line[--linelen] = '\0';
if (!parseline(line, fields))
break;
parsedtime = 0;
diff --git a/sfeed_mbox.c b/sfeed_mbox.c
index 940a056..b0a7fb5 100644
--- a/sfeed_mbox.c
+++ b/sfeed_mbox.c
@@ -67,6 +67,8 @@ printfeed(FILE *fp, const char *feedname)
ssize_t linelen;
while ((linelen = getline(&line, &linesize, fp)) > 0) {
+ if (line[linelen - 1] == '\n')
+ line[--linelen] = '\0';
if (!parseline(line, fields))
break;
parsedtime = 0;
diff --git a/sfeed_plain.c b/sfeed_plain.c
index 4de3b4d..0c6b436 100644
--- a/sfeed_plain.c
+++ b/sfeed_plain.c
@@ -16,10 +16,14 @@ printfeed(FILE *fp, const char *feedname)
{
char *fields[FieldLast];
time_t parsedtime;
+ ssize_t linelen;
- while (getline(&line, &linesize, fp) > 0) {
+ while ((linelen = getline(&line, &linesize, fp)) > 0) {
+ if (line[linelen - 1] == '\n')
+ line[--linelen] = '\0';
if (!parseline(line, fields))
break;
+
parsedtime = 0;
strtotime(fields[FieldUnixTimestamp], &parsedtime);