core: Fix handling of maximum length lines in config files.
authorCorey Farrell <git@cfware.com>
Fri, 23 Feb 2018 16:09:46 +0000 (11:09 -0500)
committerCorey Farrell <git@cfware.com>
Fri, 23 Feb 2018 17:12:04 +0000 (12:12 -0500)
When a line is the maximum length "\n" is found at sizeof(buf) - 2 since
the last character is actually the null terminator.  In addition if a
line was exactly 8190 plus a multiple of 8192 characters long the config
parser would skip the following line.

Additionally fix comment in voicemail.conf sample config.  It previously
stated that emailbody can only contain up to 512 characters which is
always wrong.  The buffer is normally 8192 characters unless LOW_MEMORY
is enabled then it is 512 characters.  The updated comment states that
the line can be up to 8190 or 510 characters since the line feed and
NULL terminator each use a character.

ASTERISK-26688 #close

Change-Id: I80864a0d40d2e2d8cd79d72af52a8f0a3a99c015

configs/samples/voicemail.conf.sample
main/config.c

index c90f851..e4130d3 100644 (file)
@@ -145,8 +145,9 @@ maxlogins=3
 ; You can select between two variables by using dialplan functions, e.g.
 ;     ${IF(${ISNULL(${ORIG_VM_DATE})}?${VM_DATE}:${ORIG_VM_DATE})}
 ;
-; Note: The emailbody config row can only be up to 512 characters due to a
-;       limitation in the Asterisk configuration subsystem.
+; Note: The emailbody config row can only be up to 8190 characters due to a
+;       limitation in the Asterisk configuration subsystem.  If compiled with
+;       LOW_MEMORY the limit is 510 characters.
 ;emailsubject=[PBX]: New message ${VM_MSGNUM} in mailbox ${VM_MAILBOX}
 ; The following definition is very close to the default, but the default shows
 ; just the CIDNAME, if it is not null, otherwise just the CIDNUM, or "an unknown
index 118b958..8107fce 100644 (file)
@@ -2195,10 +2195,10 @@ static struct ast_config *config_text_file_load(const char *database, const char
                                        lineno++;
                                        if (fgets(buf, sizeof(buf), f)) {
                                                /* Skip lines that are too long */
-                                               if (strlen(buf) == sizeof(buf) - 1 && buf[sizeof(buf) - 1] != '\n') {
+                                               if (strlen(buf) == sizeof(buf) - 1 && buf[sizeof(buf) - 2] != '\n') {
                                                        ast_log(LOG_WARNING, "Line %d too long, skipping. It begins with: %.32s...\n", lineno, buf);
                                                        while (fgets(buf, sizeof(buf), f)) {
-                                                               if (strlen(buf) != sizeof(buf) - 1 || buf[sizeof(buf) - 1] == '\n') {
+                                                               if (strlen(buf) != sizeof(buf) - 1 || buf[sizeof(buf) - 2] == '\n') {
                                                                        break;
                                                                }
                                                        }