diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-01 23:07:45 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-15 22:34:40 -0400 |
commit | 4a0a6ac03864998c83918175609275df712a5a05 (patch) | |
tree | d55f99bd39bd72afbb6a9c1091e31bee8617ad1d /src/journal-remote/journal-remote-parse.c | |
parent | e9f3d2d508bfd9fb5b54e82994bda365a71eb864 (diff) |
Fix problem with allocating large buffers and log leftovers
Diffstat (limited to 'src/journal-remote/journal-remote-parse.c')
-rw-r--r-- | src/journal-remote/journal-remote-parse.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c index a08ca2fdcb..14af55ca55 100644 --- a/src/journal-remote/journal-remote-parse.c +++ b/src/journal-remote/journal-remote-parse.c @@ -22,7 +22,7 @@ #include "journal-remote-parse.h" #include "journald-native.h" -#define LINE_CHUNK 1024u +#define LINE_CHUNK 8*1024u void source_free(RemoteSource *source) { if (!source) @@ -71,13 +71,17 @@ static int get_line(RemoteSource *source, char **line, size_t *size) { if (source->size - source->filled < LINE_CHUNK && !GREEDY_REALLOC(source->buf, source->size, - MAX(source->filled + LINE_CHUNK, DATA_SIZE_MAX))) + MIN(source->filled + LINE_CHUNK, DATA_SIZE_MAX))) return log_oom(); - assert(source->size - source->filled >= LINE_CHUNK); + assert(source->size - source->filled >= LINE_CHUNK || + source->size == DATA_SIZE_MAX); + + // FIXME: the buffer probably needs to be bigger than DATA_SIZE_MAX + // to accomodate such big fields. n = read(source->fd, source->buf + source->filled, - MAX(source->size, DATA_SIZE_MAX) - source->filled); + source->size - source->filled); if (n < 0) { if (errno != EAGAIN && errno != EWOULDBLOCK) log_error("read(%d, ..., %zd): %m", source->fd, |