From 7b7a602de7162ddaf72bf2e73ffb84aa5b9227cf Mon Sep 17 00:00:00 2001 From: Evan Zelkowitz Date: Wed, 13 Jan 2021 13:19:33 -0800 Subject: [PATCH 1/4] Change comment handling for long lines There is a 300char max buffer size on lines url sig. If there is a comment longer than this then it will show up in the next fgets. If that happens to contain an `=` then it may end up being parsed as a rule otherwise it is thrown away but has an error printed. This changes the comment handling so that if there is no `\n` seen at the end of the string in the buffer then it is assumed it is a long comment line and urlsig will continue eating the buffer until it hits a `\n` --- plugins/experimental/url_sig/url_sig.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/experimental/url_sig/url_sig.c b/plugins/experimental/url_sig/url_sig.c index d08f9da2403..6e20cc2a7d9 100644 --- a/plugins/experimental/url_sig/url_sig.c +++ b/plugins/experimental/url_sig/url_sig.c @@ -135,6 +135,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_s char line[300]; int line_no = 0; int keynum; + bool eat_comment = false; cfg = TSmalloc(sizeof(struct config)); memset(cfg, 0, sizeof(struct config)); @@ -142,7 +143,19 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_s while (fgets(line, sizeof(line), file) != NULL) { TSDebug(PLUGIN_NAME, "LINE: %s (%d)", line, (int)strlen(line)); line_no++; + + if (eat_comment) { + // Check if final char is EOL, if so we are done eating + if (line[strlen(line) - 1] == '\n') { + eat_comment = false; + } + continue; + } if (line[0] == '#' || strlen(line) <= 1) { + // Check if we have a comment longer than the full buffer if no EOL + if (line[strlen(line) - 1] != '\n') { + eat_comment = true; + } continue; } char *pos = strchr(line, '='); From f650354cd54f0c25e20805a45c58e5eb5e158de0 Mon Sep 17 00:00:00 2001 From: Evan Zelkowitz Date: Thu, 14 Jan 2021 12:27:24 -0800 Subject: [PATCH 2/4] Added a check at the end of the url_sig autest to look for a parsing error. This would indicate we failed on the long comment line --- tests/gold_tests/pluginTest/url_sig/url_sig.config | 1 + tests/gold_tests/pluginTest/url_sig/url_sig.test.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/gold_tests/pluginTest/url_sig/url_sig.config b/tests/gold_tests/pluginTest/url_sig/url_sig.config index 7c10a6b8ef7..5bcecabd307 100644 --- a/tests/gold_tests/pluginTest/url_sig/url_sig.config +++ b/tests/gold_tests/pluginTest/url_sig/url_sig.config @@ -1,3 +1,4 @@ +#This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. key0 = hV3wqyq1QxJeF76JkzHf93tuLYv_abw5 key1 = nIpyXbVqPFVN7y8yMlfgFBLnOqDSufMy key2 = 4UED1ELmHkEcXrS_7yEYPKtgUZdGWaP2 diff --git a/tests/gold_tests/pluginTest/url_sig/url_sig.test.py b/tests/gold_tests/pluginTest/url_sig/url_sig.test.py index aee7d1c1697..4be53eaff15 100644 --- a/tests/gold_tests/pluginTest/url_sig/url_sig.test.py +++ b/tests/gold_tests/pluginTest/url_sig/url_sig.test.py @@ -264,3 +264,4 @@ def sign(payload, key): # Overriding the built in ERROR check since we expect some ERROR messages ts.Disk.diags_log.Content = Testers.ContainsExpression("ERROR", "Some tests are failure tests") +ts.Disk.diags_log.Content += Testers.ExcludesExpression("Error parsing", "Verify that we can accept long comment lines") \ No newline at end of file From 3e6bbbfca83a01ec6ce53ea94251d11b721f1398 Mon Sep 17 00:00:00 2001 From: Evan Zelkowitz Date: Thu, 14 Jan 2021 12:29:15 -0800 Subject: [PATCH 3/4] Add newline for autopep8 --- tests/gold_tests/pluginTest/url_sig/url_sig.test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gold_tests/pluginTest/url_sig/url_sig.test.py b/tests/gold_tests/pluginTest/url_sig/url_sig.test.py index 4be53eaff15..07e993df860 100644 --- a/tests/gold_tests/pluginTest/url_sig/url_sig.test.py +++ b/tests/gold_tests/pluginTest/url_sig/url_sig.test.py @@ -264,4 +264,4 @@ def sign(payload, key): # Overriding the built in ERROR check since we expect some ERROR messages ts.Disk.diags_log.Content = Testers.ContainsExpression("ERROR", "Some tests are failure tests") -ts.Disk.diags_log.Content += Testers.ExcludesExpression("Error parsing", "Verify that we can accept long comment lines") \ No newline at end of file +ts.Disk.diags_log.Content += Testers.ExcludesExpression("Error parsing", "Verify that we can accept long comment lines") From 65ffcdded96f49f8d1ca56896e3bfc15e29cd8d6 Mon Sep 17 00:00:00 2001 From: Evan Zelkowitz Date: Thu, 14 Jan 2021 12:32:33 -0800 Subject: [PATCH 4/4] Remove trailing whitespace in long comment line for clang-format --- tests/gold_tests/pluginTest/url_sig/url_sig.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gold_tests/pluginTest/url_sig/url_sig.config b/tests/gold_tests/pluginTest/url_sig/url_sig.config index 5bcecabd307..7618f6c82bb 100644 --- a/tests/gold_tests/pluginTest/url_sig/url_sig.config +++ b/tests/gold_tests/pluginTest/url_sig/url_sig.config @@ -1,4 +1,4 @@ -#This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. +#This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. This is a very long test line. key0 = hV3wqyq1QxJeF76JkzHf93tuLYv_abw5 key1 = nIpyXbVqPFVN7y8yMlfgFBLnOqDSufMy key2 = 4UED1ELmHkEcXrS_7yEYPKtgUZdGWaP2