Skip to content

Conversation

@nourdouf
Copy link

@nourdouf nourdouf commented Jan 7, 2026

Summary

This PR modifies the systemd input to dynamically select the fluent bit parser based on the value of FLUENT_BIT_PARSER on the log record. This is especially useful because it allows us to specify the parser in the systemd unit file like:

LogExtraFields=FLUENT_BIT_PARSER=logfmt

This does not fix any known issues/bugs.

This change was originally introduced in this PR: #9567 by seveas. I have since picked the patch up and fixed conflicts with the latest version. We are currently manually applying this patch when we run fluent-bit on our systems so we would love to get this upstream.

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.

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

Documentation

  • 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.

Summary by CodeRabbit

  • New Features
    • The systemd plugin can now optionally parse log message contents on-the-fly, producing richer structured event payloads when a parser is configured.
  • Bug Fixes / Reliability
    • Parsing errors are handled gracefully: when parsing fails or no parser is found, the plugin continues emitting original log content to avoid data loss.

✏️ Tip: You can customize this high-level summary in your review settings.

nourdouf and others added 2 commits January 7, 2026 17:16
Co-authored-by: Dennis Kaarsemaker <seveas@github.com>
Signed-off-by: Nour Douffir <nourdouf@github.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Adds parser-aware handling to the systemd input: MESSAGE fields can be dynamically parsed by a named parser, parsed key/value maps are re-encoded into the existing log encoder, and parsing is skipped or fallen back to raw MESSAGE when parser retrieval or parsing fails.

Changes

Cohort / File(s) Summary
Systemd parser integration
plugins/in_systemd/systemd.c
Introduces parser headers and a helper to unpack parser output and re-encode into the log encoder. Threads parser, output buffer, output size, and time through systemd_enumerate_data_store call chain. Detects and skips FLUENT_BIT_PARSER metadata, performs runtime named-parser lookup, applies parser to MESSAGE, returns a distinct code when parsed content is produced, and repacks parsed fields. Adds error handling and fallback to unparsed content.

Sequence Diagram

sequenceDiagram
    participant Journal as Systemd Journal
    participant Enum as data_store enumerator
    participant Parser as Named Parser
    participant Repack as Repack Helper
    participant Encoder as Log Encoder
    participant Output as Output Buffer

    Journal->>Enum: enumerate entry (contains MESSAGE, metadata)
    activate Enum
    Enum->>Enum: extract fields (skip FLUENT_BIT_PARSER metadata)
    alt FLUENT_BIT_PARSER present
        Enum->>Parser: lookup named parser
        alt parser found
            Parser->>Parser: parse MESSAGE -> kv map / error
            alt parse success (parsed map)
                Parser-->>Repack: return parsed map
                Repack->>Encoder: unpack parsed map into encoder
            else parse failed
                Parser-->>Enum: error
                Enum->>Encoder: use original MESSAGE
            end
        else parser not found
            Parser-->>Enum: not found
            Enum->>Encoder: use original MESSAGE
        end
    else no parser configured
        Enum->>Encoder: use original MESSAGE
    end
    Encoder->>Output: emit encoded event
    deactivate Enum
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • cosmo0920

Poem

🐰 I hopped through systemd fields today,

found MESSAGE maps along my way.
I parse and pack with nimble paws,
fallback ready for any cause.
Logs now dance — a rabbit's praise! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'in_systemd: allow a parser to be specified as part of the systemd unit' directly describes the main feature added: enabling dynamic parser selection via FLUENT_BIT_PARSER field in systemd units.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @plugins/in_systemd/systemd.c:
- Around line 421-431: flb_strndup can return NULL; after calling it in the
FLUENT_BIT_PARSER block check if name == NULL and handle the allocation failure
by logging an error via flb_plg_error (e.g. "failed to allocate parser name")
and skip calling flb_parser_get and any further use of name; only call
flb_free(name) if name is non-NULL (or ensure early return/continue so name is
not used afterward). Ensure parser remains NULL when allocation fails so the
existing logic that depends on parser behaves correctly.
- Around line 105-121: The loop assumes source_map.data is a map; add a type
check before iterating: verify source_map.type (or source_map.data.type) equals
MSGPACK_OBJECT_MAP (or the appropriate msgpack type enum used in this codebase)
and only enter the for loop when that check passes; if the check fails, handle
the non-map case (skip iteration or return an error) so accesses to
source_map.data.via.map.size and .ptr are safe and then continue using
flb_log_event_encoder_append_body_msgpack_object as before.
🧹 Nitpick comments (1)
plugins/in_systemd/systemd.c (1)

184-191: Consider documenting the return code convention.

The function now returns multiple special codes (-1, -2, -3). Adding a brief comment documenting these return values would improve maintainability:

  • 0: Success
  • -1: Error
  • -2: Skip entry (no separator found)
  • -3: Parsed content available in out_buf/out_size
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e19e07e and 637a784.

📒 Files selected for processing (1)
  • plugins/in_systemd/systemd.c
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
Repo: fluent/fluent-bit PR: 9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit CMakeLists.txt, the system library preference flags are defined as FLB_PREFER_SYSTEM_LIB_ZSTD and FLB_PREFER_SYSTEM_LIB_KAFKA with the FLB_ prefix.

Applied to files:

  • plugins/in_systemd/systemd.c
🧬 Code graph analysis (1)
plugins/in_systemd/systemd.c (2)
src/flb_parser.c (2)
  • flb_parser_do (1044-1066)
  • flb_parser_get (1022-1042)
include/fluent-bit/flb_mem.h (1)
  • flb_free (126-128)
🔇 Additional comments (4)
plugins/in_systemd/systemd.c (4)

24-25: LGTM!

The new includes are appropriate for the added parser functionality and log event decoding.


217-233: LGTM!

The logic to skip FLUENT_BIT_PARSER metadata and conditionally apply parsing to the MESSAGE field is well-structured. The graceful fallback to unparsed content when parsing fails is a good resilience pattern.


513-523: LGTM!

The parsed content handling is correct. Memory is properly freed after repacking, and the defensive pbuf = NULL prevents potential double-free issues.


793-800: LGTM!

The test formatter correctly passes NULL for parser-related parameters, maintaining backward compatibility. The short-circuit evaluation in systemd_enumerate_data_store ensures no parser logic executes when parser is NULL.

@nourdouf
Copy link
Author

nourdouf commented Jan 7, 2026

Testing Details

Here is valgrind output showing no memory leaks:

sudo valgrind --leak-check=full /opt/fluent-bit-test/fluent-bit -c /tmp/fluent-bit.conf
==175014== Memcheck, a memory error detector
==175014== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==175014== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==175014== Command: /opt/fluent-bit-test/fluent-bit -c /tmp/fluent-bit.conf
==175014==
Fluent Bit v4.2.1
* Copyright (C) 2015-2025 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

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

             Fluent Bit v4.2 – Direct Routes Ahead
         Celebrating 10 Years of Open, Fluent Innovation!

[2025/11/21 14:16:41.290392265] [ info] [fluent bit] version=4.2.1, commit=0027f1e343, pid=175014
[2025/11/21 14:16:41.344637813] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2025/11/21 14:16:41.346786011] [ info] [simd    ] disabled
[2025/11/21 14:16:41.347811310] [ info] [cmetrics] version=1.0.5
[2025/11/21 14:16:41.348654909] [ info] [ctraces ] version=0.6.6
[2025/11/21 14:16:41.374625385] [ info] [input:systemd:systemd.0] initializing
[2025/11/21 14:16:41.375771383] [ info] [input:systemd:systemd.0] storage_strategy='memory' (memory only)
[2025/11/21 14:16:41.638301333] [ info] [sp] stream processor started
[2025/11/21 14:16:41.642948428] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2025/11/21 14:16:41.643092928] [ info] [output:stdout:stdout.0] worker #0 started
==175014== Warning: client switching stacks?  SP change: 0x39fcf538 --> 0x550ce80
==175014==          to suppress, use: --max-stackframe=883697336 or greater
==175014== Warning: client switching stacks?  SP change: 0x550cd68 --> 0x39fcf538
==175014==          to suppress, use: --max-stackframe=883697616 or greater
==175014== Warning: client switching stacks?  SP change: 0x39fcf538 --> 0x550cd68
==175014==          to suppress, use: --max-stackframe=883697616 or greater
==175014==          further instances of this message will not be shown.
[2025/11/21 14:16:58.969004687] [ info] [engine] pausing all inputs..
[2025/11/21 14:16:58.971914384] [ info] [input] pausing systemd.0
[2025/11/21 14:16:59.168586596] [ info] [engine] service has stopped (0 pending tasks)
[2025/11/21 14:16:59.169107296] [ info] [input] pausing systemd.0
[2025/11/21 14:16:59.173325092] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2025/11/21 14:16:59.184829181] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==175014==
==175014== HEAP SUMMARY:
==175014==     in use at exit: 0 bytes in 0 blocks
==175014==   total heap usage: 3,191 allocs, 3,191 frees, 2,596,924 bytes allocated
==175014==
==175014== All heap blocks were freed -- no leaks are possible
==175014==
==175014== For lists of detected and suppressed errors, rerun with: -s
==175014== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 637a784d62

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

This patch addresses three issues:

- Add NULL check after flb_strndup to prevent potential segfault
  when memory allocation fails
- Add type validation for msgpack object before accessing map
  fields to prevent undefined behavior with non-map data
- Fix FLUENT_BIT_PARSER counting toward max_fields limit by
  returning -1 instead of 0

Signed-off-by: Nour Douffir <nourdouf@github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @plugins/in_systemd/systemd.c:
- Around line 524-534: When ret == -3 before calling flb_systemd_repack_map,
check that pbuf is not NULL; if pbuf is NULL, skip repacking (increment no
entries), continue the loop, and avoid calling flb_systemd_repack_map with a
NULL buffer. Specifically, in the branch handling ret == -3 (around variables
pbuf, plength, ret and the call to flb_systemd_repack_map), add a defensive if
(pbuf == NULL) { continue; } (or equivalent cleanup/continue) so
flb_systemd_repack_map and msgpack_unpack_next are never invoked with a NULL
pbuf.
🧹 Nitpick comments (2)
plugins/in_systemd/systemd.c (2)

347-347: Consider initializing plength for safety.

While plength is only used after flb_parser_do sets it (line 233), initializing it to 0 at declaration improves defensive programming and makes the code more resilient to future changes.

♻️ Proposed initialization
-    size_t plength;
+    size_t plength = 0;

431-431: Consider using a named constant for field offset.

The magic number 18 represents the length of "FLUENT_BIT_PARSER=". A named constant would improve maintainability.

♻️ Proposed refactor using named constant

Add near the top of the file with other constants:

#define FLUENT_BIT_PARSER_FIELD "FLUENT_BIT_PARSER"
#define FLUENT_BIT_PARSER_FIELD_LEN 18

Then use it:

-        ret = sd_journal_get_data(ctx->j, "FLUENT_BIT_PARSER", &data, &length);
+        ret = sd_journal_get_data(ctx->j, FLUENT_BIT_PARSER_FIELD, &data, &length);
         if (ret == 0) {
-            name = flb_strndup((const char *)(data+18), length-18);
+            name = flb_strndup((const char *)(data + FLUENT_BIT_PARSER_FIELD_LEN), 
+                               length - FLUENT_BIT_PARSER_FIELD_LEN);
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 637a784 and 1e55072.

📒 Files selected for processing (1)
  • plugins/in_systemd/systemd.c
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
Repo: fluent/fluent-bit PR: 9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit CMakeLists.txt, the system library preference flags are defined as FLB_PREFER_SYSTEM_LIB_ZSTD and FLB_PREFER_SYSTEM_LIB_KAFKA with the FLB_ prefix.

Applied to files:

  • plugins/in_systemd/systemd.c
🧬 Code graph analysis (1)
plugins/in_systemd/systemd.c (1)
src/flb_parser.c (2)
  • flb_parser_do (1044-1066)
  • flb_parser_get (1022-1042)
🔇 Additional comments (5)
plugins/in_systemd/systemd.c (5)

75-132: LGTM - Type validation is now in place.

The type check at line 99 correctly validates that source_map.data.type is MSGPACK_OBJECT_MAP before the loop accesses map-specific fields. The previous issue flagged in past reviews has been addressed.


223-227: LGTM - Metadata field correctly skipped.

The return value -1 ensures FLUENT_BIT_PARSER is excluded from log content and does not count toward max_fields (caller continues at line 535 without incrementing entries). This correctly treats the field as metadata-only.


229-239: LGTM - Parser applied conditionally to MESSAGE field.

The logic correctly applies the parser only when both a parser is specified and the field is MESSAGE. Falling through to normal processing if parsing fails is a reasonable fallback.


427-442: LGTM - NULL check now prevents crash.

The NULL check at line 432 correctly handles memory allocation failure from flb_strndup, preventing the segfault that was flagged in previous reviews. The parser gracefully remains NULL on any error, allowing the MESSAGE field to be processed unparsed.


806-807: Test function correctly passes NULL for new parameters.

The test function cb_systemd_format_test appropriately passes NULL for the new parser-related parameters. Since systemd_enumerate_data_store checks parser at line 230 before use, this is safe.

Comment on lines +524 to +534
else if (ret == -3) {
/* Parsed content - add it to encoder as msgpack */
ret = flb_systemd_repack_map(ctx->log_encoder, pbuf, plength);
flb_free(pbuf);
pbuf = NULL;
if (ret != FLB_EVENT_ENCODER_SUCCESS) {
continue;
}
entries++;
continue;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add NULL check before repacking parsed content.

pbuf could theoretically be NULL even when ret == -3 if flb_parser_do succeeds but returns a NULL buffer. Passing NULL to flb_systemd_repack_map would cause msgpack_unpack_next to operate on invalid data at line 93.

🐛 Proposed fix to add defensive NULL check
             else if (ret == -3) {
                 /* Parsed content - add it to encoder as msgpack */
+                if (pbuf != NULL) {
-                ret = flb_systemd_repack_map(ctx->log_encoder, pbuf, plength);
-                flb_free(pbuf);
-                pbuf = NULL;
-                if (ret != FLB_EVENT_ENCODER_SUCCESS) {
+                    ret = flb_systemd_repack_map(ctx->log_encoder, pbuf, plength);
+                    flb_free(pbuf);
+                    pbuf = NULL;
+                    if (ret != FLB_EVENT_ENCODER_SUCCESS) {
+                        continue;
+                    }
+                    entries++;
+                }
+                else {
+                    flb_plg_error(ctx->ins, "parser succeeded but returned NULL buffer");
                     continue;
                 }
-                entries++;
                 continue;
             }
🤖 Prompt for AI Agents
In @plugins/in_systemd/systemd.c around lines 524 - 534, When ret == -3 before
calling flb_systemd_repack_map, check that pbuf is not NULL; if pbuf is NULL,
skip repacking (increment no entries), continue the loop, and avoid calling
flb_systemd_repack_map with a NULL buffer. Specifically, in the branch handling
ret == -3 (around variables pbuf, plength, ret and the call to
flb_systemd_repack_map), add a defensive if (pbuf == NULL) { continue; } (or
equivalent cleanup/continue) so flb_systemd_repack_map and msgpack_unpack_next
are never invoked with a NULL pbuf.

@cosmo0920
Copy link
Contributor

cosmo0920 commented Jan 9, 2026

@coderabbitai complains issues on your commits. Could you check them?

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch review comments made by coderabbitai on PR #11353
gh pr view 11353 --repo fluent/fluent-bit --json comments,reviews --jq '.reviews[] | select(.author.login == "coderabbitai[bot]" or .author.login == "coderabbitai") | {state: .state, body: .body, createdAt: .createdAt}'

# Also fetch review comments on specific files/lines
gh api repos/fluent/fluent-bit/pulls/11353/comments --jq '.[] | select(.user.login == "coderabbitai[bot]" or .user.login == "coderabbitai") | {path: .path, line: .line, body: .body, created_at: .created_at}'

Length of output: 17625


@cosmo0920, here's a summary of the issues I flagged in my reviews of this PR:

✅ Resolved Issues (fixed in commit 1e55072)

  1. Critical - NULL check after flb_strndup (originally line 442): Added proper NULL check to prevent crash when memory allocation fails
  2. Major - Type validation for msgpack map (originally line 126): Added type check to verify source_map.data is MSGPACK_OBJECT_MAP before accessing map fields

⚠️ Outstanding Issue

  1. Major - NULL check for pbuf before repacking (line 534):

    • When ret == -3, pbuf should be checked for NULL before calling flb_systemd_repack_map
    • Even though flb_parser_do succeeds, it could theoretically return a NULL buffer
    • Passing NULL to msgpack_unpack_next would cause invalid memory access

    Suggested fix:

    else if (ret == -3) {
        /* Parsed content - add it to encoder as msgpack */
        if (pbuf != NULL) {
            ret = flb_systemd_repack_map(ctx->log_encoder, pbuf, plength);
            flb_free(pbuf);
            pbuf = NULL;
            if (ret != FLB_EVENT_ENCODER_SUCCESS) {
                continue;
            }
            entries++;
        }
        else {
            flb_plg_error(ctx->ins, "parser succeeded but returned NULL buffer");
        }
        continue;
    }

📝 Minor Suggestions (Nitpicks)

  • Initialize plength = 0 at declaration (line 347) for defensive programming
  • Use named constant instead of magic number 18 for "FLUENT_BIT_PARSER=" length (line 431)
  • Document return code convention for the function (lines 184-191)

The main remaining concern is the NULL check for pbuf at line 534, which should be addressed to prevent potential crashes.

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch all review comments by coderabbitai on PR #11353
gh pr view 11353 --json comments,reviews --jq '.reviews[] | select(.author.login == "coderabbitai") | {state: .state, body: .body, createdAt: .createdAt}'

Length of output: 11305


🏁 Script executed:

#!/bin/bash
# Also fetch review comments (inline comments on code)
gh api repos/fluent/fluent-bit/pulls/11353/comments --jq '.[] | select(.user.login == "coderabbitai") | {path: .path, line: .line, body: .body, created_at: .created_at, diff_hunk: .diff_hunk}'

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Fetch the current code around lines 524-534 to check if the pbuf NULL check issue was addressed
cd /tmp/repo 2>/dev/null || git clone --depth 1 --branch nourdouf/add-systemd-custom-parser https://github.com/fluent/fluent-bit.git /tmp/repo
cd /tmp/repo
cat -n plugins/in_systemd/systemd.c | sed -n '515,545p'

Length of output: 1536


🏁 Script executed:

#!/bin/bash
# Check the systemd_enumerate_data_store function to understand when ret == -3 is returned
# and whether pbuf can be NULL in that case
cat -n plugins/in_systemd/systemd.c | sed -n '180,250p'

Length of output: 2758


@cosmo0920, I've reviewed my previous comments on this PR. Most of the issues have been addressed, but there is one remaining issue that needs attention:

Remaining Issue

Location: Lines 524-534 in plugins/in_systemd/systemd.c

When ret == -3 (indicating parsed content is available), the code calls flb_systemd_repack_map and flb_free with pbuf without checking if it's NULL:

else if (ret == -3) {
    /* Parsed content - add it to encoder as msgpack */
    ret = flb_systemd_repack_map(ctx->log_encoder, pbuf, plength);
    flb_free(pbuf);
    pbuf = NULL;

Issue: Although flb_parser_do (line 233) is expected to populate out_buf when returning success, defensive programming requires validating pbuf is non-NULL before dereferencing or freeing it.

Recommended fix:

else if (ret == -3) {
    /* Parsed content - add it to encoder as msgpack */
    if (pbuf == NULL) {
        skip_entries++;
        continue;
    }
    ret = flb_systemd_repack_map(ctx->log_encoder, pbuf, plength);
    flb_free(pbuf);
    pbuf = NULL;
    if (ret != FLB_EVENT_ENCODER_SUCCESS) {
        continue;
    }
    entries++;
    continue;
}

This adds a safety check to prevent potential crashes if flb_parser_do ever returns success with a NULL buffer.


Previously Fixed Issues ✅

The following issues from my earlier reviews have been successfully addressed:

  • ✅ NULL check for flb_strndup result (lines 427-442)
  • ✅ Type validation before iterating map (line 99)

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