diff options
Diffstat (limited to 'multipart-replace.c')
-rw-r--r-- | multipart-replace.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/multipart-replace.c b/multipart-replace.c index 30ae7bb..5f0ca4e 100644 --- a/multipart-replace.c +++ b/multipart-replace.c @@ -38,7 +38,6 @@ ssize_t safe_atoi(char *str) { return atoi(str); } -#define rgetline() do { if ((line_len = getline(&line_buf, &line_cap, stream)) < 0) { error(0, 0, "source hung up"); return; } } while(0) void multipart_replace_reader(struct multipart_replace_stream *s, int fd, const char *boundary) { FILE *stream = fdopen(fd, "r"); boundary = boundary_line(boundary); @@ -52,7 +51,11 @@ void multipart_replace_reader(struct multipart_replace_stream *s, int fd, const content_length = -1; /* scan for the first non-empty line */ do { - rgetline(); + line_len = getline(&line_buf, &line_cap, stream); + if (line_len < 0) { + error(0, 0, "source hung up"); + return; + } } while (strcmp(line_buf, "\r\n") == 0); /* make sure it matches the boundary separator */ if (strcmp(line_buf, boundary) != 0) { @@ -61,7 +64,11 @@ void multipart_replace_reader(struct multipart_replace_stream *s, int fd, const } /* read the frame header (MIME headers) */ do { - rgetline(); + line_len = getline(&line_buf, &line_cap, stream); + if (line_len < 0) { + error(0, 0, "source hung up"); + return; + } /* append the line to the frame contents */ if ((ssize_t)s->back->cap < s->back->len + line_len) s->back->buf = xrealloc(s->back->buf, s->back->cap = s->back->len + line_len); @@ -80,7 +87,7 @@ void multipart_replace_reader(struct multipart_replace_stream *s, int fd, const /* read the frame contents */ if ((ssize_t)s->back->cap < s->back->len + content_length) s->back->buf = xrealloc(s->back->buf, s->back->cap = s->back->len + content_length); - if (fread(s->back->buf, s->back->len, 1, stream) != 1) { + if (fread(&s->back->buf[s->back->len], content_length, 1, stream) != 1) { error(0, ferror(stream), "fread(%zd)", s->back->len); return; } |