conf-parse: remove 4K line length limit

Let's use read_line() to solve our long line limitation.

Fixes #3302.
This commit is contained in:
Lennart Poettering 2017-09-22 18:26:35 +02:00 committed by Zbigniew Jędrzejewski-Szmek
parent e3f46367f5
commit e6dde451a5
1 changed files with 32 additions and 11 deletions

View File

@ -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"
@ -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 log_error_errno(errno, "Failed to read configuration file '%s': %m", filename);
return r;
}
if (r < 0) {
if (warn)
log_error_errno(r, "%s:%u: Error while reading configuration file: %m", filename, line);
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)
@ -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;
}
}