[Asterisk-code-review] config.c: Skip UTF-8 BOMs if present when reading config files (asterisk[13])

Sean Bright asteriskteam at digium.com
Thu Dec 19 04:36:43 CST 2019


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/13457 )


Change subject: config.c: Skip UTF-8 BOMs if present when reading config files
......................................................................

config.c: Skip UTF-8 BOMs if present when reading config files

ASTERISK-28667 #close

Change-Id: I4767ed365c98f3e1587b7653321048a31d8a53b2
---
M main/config.c
1 file changed, 12 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/13457/1

diff --git a/main/config.c b/main/config.c
index 8731ebb..ede7db2 100644
--- a/main/config.c
+++ b/main/config.c
@@ -2223,6 +2223,18 @@
 							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[3], line_bytes - bom_bytes + 1);
+							}
+#undef UTF8_BOM
+						}
+
 						if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)
 							&& lline_buffer
 							&& ast_str_strlen(lline_buffer)) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13457
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I4767ed365c98f3e1587b7653321048a31d8a53b2
Gerrit-Change-Number: 13457
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20191219/f00d6357/attachment.html>


More information about the asterisk-code-review mailing list