Prevent crashes from occurring when reading from data sources with large values
[asterisk/asterisk.git] / main / config.c
index f56421e..cf2b84c 100644 (file)
@@ -1646,6 +1646,17 @@ static struct ast_config *config_text_file_load(const char *database, const char
                while (!feof(f)) {
                        lineno++;
                        if (fgets(buf, sizeof(buf), f)) {
+                               /* Skip lines that are too long */
+                               if (strlen(buf) == sizeof(buf) - 1 && buf[sizeof(buf) - 1] != '\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') {
+                                                       break;
+                                               }
+                                       }
+                                       continue;
+                               }
+
                                if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && lline_buffer && ast_str_strlen(lline_buffer)) {
                                        CB_ADD(&comment_buffer, ast_str_buffer(lline_buffer));       /* add the current lline buffer to the comment buffer */
                                        ast_str_reset(lline_buffer);        /* erase the lline buffer */