Skip to content

filter_geoip2: fix lookup key comparison - #12237

Open
sbruder wants to merge 1 commit into
fluent:masterfrom
sbruder:filter-geoip2-fix-lookup-key-cmp
Open

filter_geoip2: fix lookup key comparison#12237
sbruder wants to merge 1 commit into
fluent:masterfrom
sbruder:filter-geoip2-fix-lookup-key-cmp

Conversation

@sbruder

@sbruder sbruder commented Aug 5, 2026

Copy link
Copy Markdown

This patch fixes the problem that when a key with the same prefix as the lookup key existed, the filter could choose the wrong one, as the comparison was limited to the length of the specified lookup key.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Output prior to the change

Attachments:

$ echo '{"address": "8.8.8.8", "bddress_type": "ipv4"}'"\n"'{"address": "8.8.8.8", "address_type": "ipv4"}' | podman run --rm -i -v /tmp/dbip-asn-lite.mmdb:/tmp/dbip-asn-lite.mmdb fluent-bit /fluent-bit/bin/fluent-bit -i stdin -F geoip2 -m "*" -p database=/tmp/dbip-asn-lite.mmdb -p lookup_key=address -p record="address_asn address %{autonomous_system_number}" -o stdout
Fluent Bit v5.1.0
* Copyright (C) 2015-2026 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

______ _                  _    ______ _ _           _____  _____ 
|  ___| |                | |   | ___ (_) |         |  ___||  _  |
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   _|___ \ | |/' |
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / /   \ \|  /| |
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V //\__/ /\ |_/ /
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/ \____(_)\___/


[2026/08/05 20:07:05.750] [ info] [fluent bit] version=5.1.0, commit=fe293d4270, pid=1
[2026/08/05 20:07:05.751] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2026/08/05 20:07:05.751] [ info] [simd    ] SSE2
[2026/08/05 20:07:05.751] [ info] [cmetrics] version=2.2.1
[2026/08/05 20:07:05.751] [ info] [ctraces ] version=0.7.1
[2026/08/05 20:07:05.751] [ info] [input:stdin:stdin.0] initializing
[2026/08/05 20:07:05.751] [ info] [input:stdin:stdin.0] storage_strategy='memory' (memory only)
[2026/08/05 20:07:05.751] [ info] [sp] stream processor started
[2026/08/05 20:07:05.751] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2026/08/05 20:07:05.751] [ info] [output:stdout:stdout.0] worker #0 started
[2026/08/05 20:07:05.768] [error] [filter:geoip2:geoip2.0] getaddrinfo failed: Name or service not known
[2026/08/05 20:07:05.768] [ warn] [input:stdin:stdin.0] end of file (stdin closed by remote end)
[2026/08/05 20:07:05.768] [ warn] [engine] service will shutdown in max 5 seconds
[2026/08/05 20:07:05.768] [ info] [engine] pausing all inputs..
[0] stdin.0: [[1785960425.768110083, {}], {"address"=>"8.8.8.8", "bddress_type"=>"ipv4", "address_asn"=>15169}]
[1] stdin.0: [[1785960425.768117527, {}], {"address"=>"8.8.8.8", "address_type"=>"ipv4", "address_asn"=>nil}]
[2026/08/05 20:07:06.562] [ info] [engine] service has stopped (0 pending tasks)
[2026/08/05 20:07:06.562] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2026/08/05 20:07:06.562] [ info] [output:stdout:stdout.0] thread worker #0 stopped
Output after the change
$ echo '{"address": "8.8.8.8", "bddress_type": "ipv4"}'"\n"'{"address": "8.8.8.8", "address_type": "ipv4"}' | podman run --rm -i -v /tmp/dbip-asn-lite.mmdb:/tmp/dbip-asn-lite.mmdb fluent-bit /fluent-bit/bin/fluent-bit -i stdin -F geoip2 -m "*" -p database=/tmp/dbip-asn-lite.mmdb -p lookup_key=address -p record="address_asn address %{autonomous_system_number}" -o stdout 
Fluent Bit v5.1.0
* Copyright (C) 2015-2026 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

______ _                  _    ______ _ _           _____  _____ 
|  ___| |                | |   | ___ (_) |         |  ___||  _  |
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   _|___ \ | |/' |
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / /   \ \|  /| |
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V //\__/ /\ |_/ /
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/ \____(_)\___/


[2026/08/05 20:08:31.055] [ info] [fluent bit] version=5.1.0, commit=fe293d4270, pid=1
[2026/08/05 20:08:31.056] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2026/08/05 20:08:31.056] [ info] [simd    ] SSE2
[2026/08/05 20:08:31.056] [ info] [cmetrics] version=2.2.1
[2026/08/05 20:08:31.056] [ info] [ctraces ] version=0.7.1
[2026/08/05 20:08:31.056] [ info] [input:stdin:stdin.0] initializing
[2026/08/05 20:08:31.056] [ info] [input:stdin:stdin.0] storage_strategy='memory' (memory only)
[2026/08/05 20:08:31.056] [ info] [sp] stream processor started
[2026/08/05 20:08:31.056] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2026/08/05 20:08:31.056] [ info] [output:stdout:stdout.0] worker #0 started
[2026/08/05 20:08:31.068] [ warn] [input:stdin:stdin.0] end of file (stdin closed by remote end)
[2026/08/05 20:08:31.068] [ warn] [engine] service will shutdown in max 5 seconds
[2026/08/05 20:08:31.068] [ info] [engine] pausing all inputs..
[0] stdin.0: [[1785960511.068764694, {}], {"address"=>"8.8.8.8", "bddress_type"=>"ipv4", "address_asn"=>15169}]
[1] stdin.0: [[1785960511.068769403, {}], {"address"=>"8.8.8.8", "address_type"=>"ipv4", "address_asn"=>15169}]
[2026/08/05 20:08:31.561] [ info] [engine] service has stopped (0 pending tasks)
[2026/08/05 20:08:31.562] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2026/08/05 20:08:31.562] [ info] [output:stdout:stdout.0] thread worker #0 stopped
Valgrind output
$ echo '{"address": "8.8.8.8", "bddress_type": "ipv4"}'"\n"'{"address": "8.8.8.8", "address_type": "ipv4"}' | podman run --rm -i -v /tmp/dbip-asn-lite.mmdb:/tmp/dbip-asn-lite.mmdb fluent-bit valgrind --leak-check=full /fluent-bit/bin/fluent-bit -i stdin -F geoip2 -m "*" -p database=/tmp/dbip-asn-lite.mmdb -p lookup_key=address -p record="address_asn address %{autonomous_system_number}" -o stdout
==1== Memcheck, a memory error detector
==1== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==1== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==1== Command: /fluent-bit/bin/fluent-bit -i stdin -F geoip2 -m * -p database=/tmp/dbip-asn-lite.mmdb -p lookup_key=address -p record=address_asn\ address\ %{autonomous_system_number} -o stdout
==1== 
Fluent Bit v5.1.0
* Copyright (C) 2015-2026 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

______ _                  _    ______ _ _           _____  _____ 
|  ___| |                | |   | ___ (_) |         |  ___||  _  |
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   _|___ \ | |/' |
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / /   \ \|  /| |
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V //\__/ /\ |_/ /
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/ \____(_)\___/


==1== Warning: client switching stacks?  SP change: 0x9114558 --> 0x64ab5c0
==1==          to suppress, use: --max-stackframe=46567320 or greater
==1== Warning: client switching stacks?  SP change: 0x64ab558 --> 0x9114558
==1==          to suppress, use: --max-stackframe=46567424 or greater
==1== Warning: client switching stacks?  SP change: 0x9114558 --> 0x64ab558
==1==          to suppress, use: --max-stackframe=46567424 or greater
==1==          further instances of this message will not be shown.
[0] stdin.0: [[1785960310.971641418, {}], {"address"=>"8.8.8.8", "bddress_type"=>"ipv4", "address_asn"=>15169}]
[1] stdin.0: [[1785960310.975738255, {}], {"address"=>"8.8.8.8", "address_type"=>"ipv4", "address_asn"=>15169}]
[2026/08/05 20:05:10.843] [ info] [fluent bit] version=5.1.0, commit=fe293d4270, pid=1
[2026/08/05 20:05:10.873] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2026/08/05 20:05:10.874] [ info] [simd    ] SSE2
[2026/08/05 20:05:10.874] [ info] [cmetrics] version=2.2.1
[2026/08/05 20:05:10.875] [ info] [ctraces ] version=0.7.1
[2026/08/05 20:05:10.886] [ info] [input:stdin:stdin.0] initializing
[2026/08/05 20:05:10.887] [ info] [input:stdin:stdin.0] storage_strategy='memory' (memory only)
[2026/08/05 20:05:10.956] [ info] [sp] stream processor started
[2026/08/05 20:05:10.958] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2026/08/05 20:05:11.009] [ warn] [input:stdin:stdin.0] end of file (stdin closed by remote end)
[2026/08/05 20:05:11.017] [ warn] [engine] service will shutdown in max 5 seconds
[2026/08/05 20:05:11.018] [ info] [engine] pausing all inputs..
[2026/08/05 20:05:11.024] [ info] [output:stdout:stdout.0] worker #0 started
[2026/08/05 20:05:11.569] [ info] [engine] service has stopped (0 pending tasks)
[2026/08/05 20:05:11.580] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2026/08/05 20:05:11.583] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==1== 
==1== HEAP SUMMARY:
==1==     in use at exit: 0 bytes in 0 blocks
==1==   total heap usage: 6,407 allocs, 6,407 frees, 1,355,693 bytes allocated
==1== 
==1== All heap blocks were freed -- no leaks are possible
==1== 
==1== For lists of detected and suppressed errors, rerun with: -s
==1== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Summary by CodeRabbit

  • Bug Fixes
    • Improved GeoIP2 lookup matching to compare complete keys without regard to letter casing.
    • Prevented partial or prefix matches from returning incorrect results.

This patch fixes the problem that when a key with the same prefix as the
lookup key existed, the filter could choose the wrong one, as the
comparison was limited to the length of the specified lookup key.

Signed-off-by: Simon Bruder <simon@sbruder.de>
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1e7cccaf-5439-4899-8ebf-8f812872fc4c

📥 Commits

Reviewing files that changed from the base of the PR and between fe293d4 and 637883d.

📒 Files selected for processing (1)
  • plugins/filter_geoip2/geoip2.c

📝 Walkthrough

Walkthrough

Changes

GeoIP2 lookup matching

Layer / File(s) Summary
Update lookup key comparison
plugins/filter_geoip2/geoip2.c
prepare_lookup_keys now uses flb_sds_casecmp for case-insensitive full-string matching instead of prefix matching.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: cosmo0920

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the lookup key comparison fix in the filter_geoip2 plugin.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cosmo0920 cosmo0920 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable but can we add a test case for confirming regressions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants