Bail out if a configuration file starts with a byte order mark
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Sun, 25 Jun 2017 21:35:06 +0000 (23:35 +0200)
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Sun, 25 Jun 2017 21:48:33 +0000 (23:48 +0200)
src/src/readconf.c
test/confs/0907 [new file with mode: 0644]
test/confs/0908 [new file with mode: 0644]
test/scripts/0000-Basic/0907 [new file with mode: 0644]
test/scripts/0000-Basic/0908 [new symlink]
test/stderr/0907 [new file with mode: 0644]
test/stderr/0908 [new file with mode: 0644]

index 95abaf5..fd9657e 100644 (file)
@@ -3469,6 +3469,11 @@ a macro definition. */
 
 while ((s = get_config_line()) != NULL)
   {
 
 while ((s = get_config_line()) != NULL)
   {
+
+  if (config_lineno == 1 && Ustrstr(s, "\xef\xbb\xbf") == s)
+    log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
+      "found unexpected BOM (Byte Order Mark)");
+
   if (isupper(s[0])) read_macro_assignment(s);
 
   else if (Ustrncmp(s, "domainlist", 10) == 0)
   if (isupper(s[0])) read_macro_assignment(s);
 
   else if (Ustrncmp(s, "domainlist", 10) == 0)
diff --git a/test/confs/0907 b/test/confs/0907
new file mode 100644 (file)
index 0000000..8cb2b1b
--- /dev/null
@@ -0,0 +1,3 @@
+# This file contains a BOM at the very beginning
+tls_advertise_hosts =
+keep_environment =
diff --git a/test/confs/0908 b/test/confs/0908
new file mode 100644 (file)
index 0000000..27af1d5
--- /dev/null
@@ -0,0 +1 @@
+.include DIR/confs/0907
diff --git a/test/scripts/0000-Basic/0907 b/test/scripts/0000-Basic/0907
new file mode 100644 (file)
index 0000000..341a63f
--- /dev/null
@@ -0,0 +1,4 @@
+# check for BOM in an included config file (0908)
+#
+1
+exim -bP config
diff --git a/test/scripts/0000-Basic/0908 b/test/scripts/0000-Basic/0908
new file mode 120000 (symlink)
index 0000000..8cc1a8c
--- /dev/null
@@ -0,0 +1 @@
+0907
\ No newline at end of file
diff --git a/test/stderr/0907 b/test/stderr/0907
new file mode 100644 (file)
index 0000000..fe9ba71
--- /dev/null
@@ -0,0 +1,2 @@
+1999-03-02 09:44:33 Exim configuration error in line 1 of TESTSUITE/test-config:
+  found unexpected BOM (Byte Order Mark)
diff --git a/test/stderr/0908 b/test/stderr/0908
new file mode 100644 (file)
index 0000000..ad35a1a
--- /dev/null
@@ -0,0 +1,2 @@
+1999-03-02 09:44:33 Exim configuration error in line 1 of TESTSUITE/confs/0907:
+  found unexpected BOM (Byte Order Mark)