From acc2d6dc1db4a3841ad4b9fae56af3420278866c Mon Sep 17 00:00:00 2001 From: Rafay Qayyum Date: Sun, 15 Nov 2026 18:19:56 +0500 Subject: [PATCH] parser_syslog: anchor the RFC 5424 header regexp at the match position Signed-off-by: Rafay Qayyum --- lib/fluent/plugin/parser_syslog.rb | 2 +- test/plugin/test_parser_syslog.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/parser_syslog.rb b/lib/fluent/plugin/parser_syslog.rb index 52c3b1f066..d2310af1ef 100644 --- a/lib/fluent/plugin/parser_syslog.rb +++ b/lib/fluent/plugin/parser_syslog.rb @@ -44,7 +44,7 @@ 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 + 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..57fedb75b5 100644 --- a/test/plugin/test_parser_syslog.rb +++ b/test/plugin/test_parser_syslog.rb @@ -530,6 +530,20 @@ def test_parse_does_not_accept_space_after_rfc5424_priority(data) assert_input_rejected(text, expectation) end + data( + 'non-ASCII host' => '<14>1 2026-04-25T16:43:29Z hôst app 123 ID - msg', + 'header on a later line' => "<14>1 2026-04-25T16:43:29Z first line\nhost app 123 ID - second line", + ) + def test_regexp_engine_does_not_match_rfc5424_header_later_in_the_message(text) + @parser.configure( + 'parser_engine' => 'regexp', + 'message_format' => 'rfc5424', + 'with_priority' => true, + ) + + assert_input_rejected(text, :rejects) + end + def test_parse_rfc5424_with_space_containing_time_format @parser.configure( 'parser_engine' => 'string',