Skip to content

Commit

Permalink
Change comment handling for long lines in url_sig plugin (apache#7421)
Browse files Browse the repository at this point in the history
 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`
  • Loading branch information
ezelkow1 committed Jan 15, 2021
1 parent 0ce2a09 commit 08fe521
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions plugins/experimental/url_sig/url_sig.c
Expand Up @@ -135,14 +135,27 @@ 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));

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, '=');
Expand Down
1 change: 1 addition & 0 deletions 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
Expand Down
1 change: 1 addition & 0 deletions tests/gold_tests/pluginTest/url_sig/url_sig.test.py
Expand Up @@ -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")

0 comments on commit 08fe521

Please sign in to comment.