]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
config.c: Skip UTF-8 BOMs if present when reading config files
authorSean Bright <sean.bright@gmail.com>
Wed, 18 Dec 2019 15:13:21 +0000 (10:13 -0500)
committerSean Bright <sean.bright@gmail.com>
Thu, 19 Dec 2019 10:48:37 +0000 (05:48 -0500)
ASTERISK-28667 #close

Change-Id: I4767ed365c98f3e1587b7653321048a31d8a53b2

main/config.c

index 8731ebb40dd35f3a40e3030f21805a729ab241c4..b3257817008725d1b514a04e01e824eccaecda29 100644 (file)
@@ -2223,6 +2223,18 @@ static struct ast_config *config_text_file_load(const char *database, const char
                                                        continue;
                                                }
 
+                                               /* If there is a UTF-8 BOM, skip over it */
+                                               if (lineno == 1) {
+#define UTF8_BOM "\xEF\xBB\xBF"
+                                                       size_t line_bytes = strlen(buf);
+                                                       size_t bom_bytes = sizeof(UTF8_BOM) - 1;
+                                                       if (line_bytes >= bom_bytes
+                                                          && !memcmp(buf, UTF8_BOM, bom_bytes)) {
+                                                               memmove(buf, &buf[bom_bytes], line_bytes - bom_bytes + 1);
+                                                       }
+#undef UTF8_BOM
+                                               }
+
                                                if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)
                                                        && lline_buffer
                                                        && ast_str_strlen(lline_buffer)) {