From aca90852f2ed94bf2bed0c009fc6f9c032fa6fa1 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Fri, 13 Nov 2026 23:25:12 -0300 Subject: [PATCH 1/2] in_syslog: Treat a PRI above 191 as invalid in_syslog built the tag from FACILITY_MAP[pri >> 3] without checking the range. For a PRI above 191 the facility was nil, so <200> was emitted with the tag syslog..emerg. With with_priority false, the PRI comes from SYSLOG_REGEXP with any number of digits, so <1234> gave syslog..crit. RFC 5424 limits PRI to 0..191. Warn and drop such a message, or emit it as unmatched with emit_unmatched_lines, like other invalid messages. The space test used <1234> as a valid PRI, so it now uses <134>. Fixes #5632 Signed-off-by: Lucas Barros --- lib/fluent/plugin/in_syslog.rb | 9 +++++++++ test/plugin/test_in_syslog.rb | 24 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/in_syslog.rb b/lib/fluent/plugin/in_syslog.rb index 1b94f4ded1..734bc0196c 100644 --- a/lib/fluent/plugin/in_syslog.rb +++ b/lib/fluent/plugin/in_syslog.rb @@ -28,6 +28,7 @@ class SyslogInput < Input DEFAULT_PARSER = 'syslog' SYSLOG_REGEXP = /\A\<([0-9]+)\>(.*)/ + PRI_RANGE = 0..191 FACILITY_MAP = { 0 => 'kern', @@ -322,6 +323,14 @@ def message_handler(data, sock) end pri ||= record.delete('pri') + # RFC 5424 limits PRI to 0..191. A larger value has no facility. + unless PRI_RANGE.cover?(pri) + if @emit_unmatched_lines + emit_unmatched(data, sock) + end + log.warn "invalid syslog priority", data: data + return + end facility = FACILITY_MAP[pri >> 3] severity = SEVERITY_MAP[pri & 0b111] diff --git a/test/plugin/test_in_syslog.rb b/test/plugin/test_in_syslog.rb index 2a0a9409dd..e1c57be2d6 100755 --- a/test/plugin/test_in_syslog.rb +++ b/test/plugin/test_in_syslog.rb @@ -181,8 +181,8 @@ def test_space_after_input_owned_priority_preserves_input_priority_syntax(parser ].join("\n")) messages = [ - '<1234>Apr 25 16:43:29 host app: message', - '<1234> Apr 25 16:43:29 host app: message', + '<134>Apr 25 16:43:29 host app: message', + '<134> Apr 25 16:43:29 host app: message', ' Apr 25 16:43:29 host app: message', ] d.run(expect_emits: 3) do @@ -218,6 +218,26 @@ def test_priority_on_a_later_line_is_unmatched_when_input_parses_priority assert_equal(message, d.events[0][2]['unmatched_line']) end + data('with_priority' => [], + 'without_priority' => ['', ' @type syslog', ' with_priority false', '']) + def test_priority_out_of_range_is_unmatched(parse_conf) + d = create_driver(([ipv4_config, 'emit_unmatched_lines true'] + parse_conf).join("\n")) + + messages = [ + '<200>Apr 25 16:43:29 host app: msg', + '<1234>Apr 25 16:43:29 host app: msg', + '<191>Apr 25 16:43:29 host app: msg', + ] + d.run(expect_emits: 3) do + u = UDPSocket.new + u.connect('127.0.0.1', @port) + messages.each { |message| u.send(message, 0) } + end + + assert_equal(['syslog.unmatched', 'syslog.unmatched', 'syslog.local7.debug'], d.events.map { |tag, _time, _record| tag }) + assert_equal(messages[0, 2], d.events[0, 2].map { |_tag, _time, record| record['unmatched_line'] }) + end + def test_msg_size d = create_driver tests = create_test_case From c070e5a56725c4248369290b4b66c63850810533 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Sun, 15 Nov 2026 23:51:14 -0300 Subject: [PATCH 2/2] test_in_syslog: Keep the 4-digit PRI case and test 192 at the boundary Signed-off-by: Lucas Barros --- test/plugin/test_in_syslog.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/plugin/test_in_syslog.rb b/test/plugin/test_in_syslog.rb index e1c57be2d6..bb93abbb24 100755 --- a/test/plugin/test_in_syslog.rb +++ b/test/plugin/test_in_syslog.rb @@ -181,8 +181,8 @@ def test_space_after_input_owned_priority_preserves_input_priority_syntax(parser ].join("\n")) messages = [ - '<134>Apr 25 16:43:29 host app: message', - '<134> Apr 25 16:43:29 host app: message', + '<0134>Apr 25 16:43:29 host app: message', + '<0134> Apr 25 16:43:29 host app: message', ' Apr 25 16:43:29 host app: message', ] d.run(expect_emits: 3) do @@ -224,7 +224,7 @@ def test_priority_out_of_range_is_unmatched(parse_conf) d = create_driver(([ipv4_config, 'emit_unmatched_lines true'] + parse_conf).join("\n")) messages = [ - '<200>Apr 25 16:43:29 host app: msg', + '<192>Apr 25 16:43:29 host app: msg', '<1234>Apr 25 16:43:29 host app: msg', '<191>Apr 25 16:43:29 host app: msg', ]