diff --git a/lib/fluent/plugin/parser_syslog.rb b/lib/fluent/plugin/parser_syslog.rb index 52c3b1f066..f9befbb314 100644 --- a/lib/fluent/plugin/parser_syslog.rb +++ b/lib/fluent/plugin/parser_syslog.rb @@ -44,7 +44,9 @@ class SyslogParser < Parser RFC3164_CAPTURES = RFC3164_WITHOUT_TIME_AND_PRI_REGEXP.names.freeze RFC3164_PRI_REGEXP = /\A<(?[0-9]{1,3})>/ - RFC5424_WITHOUT_TIME_AND_PRI_REGEXP = /(?[!-~]{1,255}) (?[!-~]{1,48}) (?[!-~]{1,128}) (?[!-~]{1,32}) (?(?:\-|(?:\[.*?(?.+))?\z/m + # \G anchors the match at the position given to Regexp#match, so a header + # that doesn't match there is rejected instead of matched further on. + RFC5424_WITHOUT_TIME_AND_PRI_REGEXP = /\G(?[!-~]{1,255}) (?[!-~]{1,48}) (?[!-~]{1,128}) (?[!-~]{1,32}) (?(?:\-|(?:\[.*?(?.+))?\z/m RFC5424_CAPTURES = RFC5424_WITHOUT_TIME_AND_PRI_REGEXP.names.freeze RFC5424_PRI_REGEXP = /\A<(?\d{1,3})>\d\d{0,2}\s/ diff --git a/test/plugin/test_parser_syslog.rb b/test/plugin/test_parser_syslog.rb index a96dd360ed..f2009ba740 100644 --- a/test/plugin/test_parser_syslog.rb +++ b/test/plugin/test_parser_syslog.rb @@ -871,6 +871,19 @@ def test_parse_with_rfc5424_message_includes_right_bracket(param) end end + data( + 'non-ASCII hostname' => '<14>1 2026-04-25T16:43:29Z hôst app 123 ID - msg', + 'header fields after a line break' => "<14>1 2026-04-25T16:43:29Z first line\nhost app 123 ID - second line", + ) + def test_parse_with_rfc5424_regexp_does_not_skip_unmatched_header(text) + @parser.configure( + 'message_format' => 'rfc5424', + 'with_priority' => true, + 'parser_engine' => 'regexp' + ) + assert_input_rejected(text, :rejects) + end + data( 'regexp/with message' => ['regexp', '[x@1 a="b\] c"]', 'msg'], 'string/with message' => ['string', '[x@1 a="b\] c"]', 'msg'],