Skip to content

Commit

Permalink
conf-parse: remove 4K line length limit
Browse files Browse the repository at this point in the history
Let's use read_line() to solve our long line limitation.

Fixes systemd#3302.
  • Loading branch information
poettering authored and keszybz committed Sep 23, 2017
1 parent e3f4636 commit e6dde45
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/shared/conf-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
#include "alloc-util.h"
#include "conf-files.h"
#include "conf-parser.h"
#include "def.h"
#include "extract-word.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "log.h"
#include "macro.h"
Expand Down Expand Up @@ -316,24 +318,44 @@ int config_parse(const char *unit,
fd_warn_permissions(filename, fileno(f));

for (;;) {
char buf[LINE_MAX], *l, *p, *c = NULL, *e;
_cleanup_free_ char *buf = NULL;
char *l, *p, *c = NULL, *e;
bool escaped = false;

if (!fgets(buf, sizeof buf, f)) {
if (feof(f))
break;
r = read_line(f, LONG_LINE_MAX, &buf);
if (r == 0)
break;
if (r == -ENOBUFS) {
if (warn)
log_error_errno(r, "%s:%u: Line too long", filename, line);

return r;
}
if (r < 0) {
if (warn)
log_error_errno(r, "%s:%u: Error while reading configuration file: %m", filename, line);

return log_error_errno(errno, "Failed to read configuration file '%s': %m", filename);
return r;
}

l = buf;
if (allow_bom && startswith(l, UTF8_BYTE_ORDER_MARK))
l += strlen(UTF8_BYTE_ORDER_MARK);
allow_bom = false;
if (allow_bom) {
char *q;

truncate_nl(l);
q = startswith(buf, UTF8_BYTE_ORDER_MARK);
if (q) {
l = q;
allow_bom = false;
}
}

if (continuation) {
if (strlen(continuation) + strlen(l) > LONG_LINE_MAX) {
if (warn)
log_error("%s:%u: Continuation line too long", filename, line);
return -ENOBUFS;
}

c = strappend(continuation, l);
if (!c) {
if (warn)
Expand Down Expand Up @@ -387,8 +409,7 @@ int config_parse(const char *unit,

if (r < 0) {
if (warn)
log_warning_errno(r, "Failed to parse file '%s': %m",
filename);
log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line);
return r;
}
}
Expand Down

0 comments on commit e6dde45

Please sign in to comment.