summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-03-21 23:34:13 -0400
committerSven Eden <yamakuzure@gmx.net>2017-06-16 10:12:57 +0200
commit79f892872f95554d867718b70e581431c815cb06 (patch)
treeda24987db9e67b13ec699ea35fda6154a03ba441 /src/shared
parent0d904a6edf6566ed403e75f835f7cc03829e336e (diff)
Ignore BOM in config files
Fixes #2823. Also remove unnecessary feof check.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/conf-parser.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 66c07a223..9c1a02241 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -294,7 +294,7 @@ int config_parse(const char *unit,
_cleanup_free_ char *section = NULL, *continuation = NULL;
_cleanup_fclose_ FILE *ours = NULL;
unsigned line = 0, section_line = 0;
- bool section_ignored = false;
+ bool section_ignored = false, allow_bom = true;
int r;
assert(filename);
@@ -314,11 +314,11 @@ int config_parse(const char *unit,
fd_warn_permissions(filename, fileno(f));
- while (!feof(f)) {
- char l[LINE_MAX], *p, *c = NULL, *e;
+ for (;;) {
+ char buf[LINE_MAX], *l, *p, *c = NULL, *e;
bool escaped = false;
- if (!fgets(l, sizeof(l), f)) {
+ if (!fgets(buf, sizeof buf, f)) {
if (feof(f))
break;
@@ -326,6 +326,11 @@ int config_parse(const char *unit,
return -errno;
}
+ l = buf;
+ if (allow_bom && startswith(l, UTF8_BYTE_ORDER_MARK))
+ l += strlen(UTF8_BYTE_ORDER_MARK);
+ allow_bom = false;
+
truncate_nl(l);
if (continuation) {