Skip to content

upstream_ha: YAML upstream files keep only the last group and can destroy an uninitialized pointer #12788

Done

Description

@eschabell

Bug Report

Describe the bug

flb_upstream_ha_from_file() (src/flb_upstream_ha.c) handles YAML upstream files incorrectly in two ways.

  1. Only the last group is used, and the others leak. The YAML branch loops over every entry in upstream_servers and assigns each new group to the same ups pointer:

    mk_list_foreach(head, &cf->upstream_servers) {
        ...
        ups = flb_upstream_ha_create(tmp);
        ...
    }

    If the file defines more than one group, the function returns only the last group, and the earlier groups are never destroyed. No error or warning is logged. If node creation fails in a later group, the error path destroys only the current group, so the earlier groups leak there too.

  2. A YAML file without groups uses an uninitialized pointer. ups is declared without an initializer (struct flb_upstream_ha *ups;). If the YAML file has no upstream_servers entries, the loop body never runs, c stays 0, and the c == 0 path calls flb_upstream_ha_destroy(ups) on that uninitialized pointer. The same path is reached if the file isn't recognized as either classic or YAML format, for example a YAML file on a build without FLB_HAVE_LIBYAML.

Both were found by reading the code on master; I haven't run them under a debugger or Valgrind. The YAML branch was added in d2569b2 (first released in v3.2.0) and is unchanged since.

The classic format isn't affected: it reads exactly one [UPSTREAM] section, and ups is always set before the c == 0 check.

To Reproduce

Issue 1: upstream file upstream.yaml:

upstream_servers:
  - name: group-a
    nodes:
      - name: a-1
        host: 127.0.0.1
        port: 24224

  - name: group-b
    nodes:
      - name: b-1
        host: 127.0.0.1
        port: 24225

Main configuration:

pipeline:
  inputs:
    - name: dummy
      tag: test
  outputs:
    - name: forward
      match: '*'
      upstream: upstream.yaml

All records go to port 24225 (group-b). group-a is ignored without a message, and running under Valgrind should report the group-a allocations as leaked.

Issue 2: an upstream file that parses as YAML but has no upstream_servers entries, for example:

service:
  log_level: info

Expected behavior

  • A file with more than one group either fails at startup with a clear error or documents and logs which group is used, without leaking the others.
  • ups is initialized to NULL, and the c == 0 path only destroys it when it's set.

Your Environment

  • Version used: master (27d56241b); YAML branch present since v3.2.0
  • Configuration: see above
  • Filters and plugins: out_forward and out_es both load upstream files through flb_upstream_ha_from_file()

Additional context

The YAML upstream servers page in fluent-bit-docs showed two groups in one file, which led readers to configure files that silently lose a group. A docs fix is in progress.

Activity

  1. eschabell commented on Nov 14, 2026

    @eschabell
    ContributorAuthor
  2. added this to the Fluent Bit v5.2.1 milestone on Nov 16, 2026
  3. edsiper commented on Nov 20, 2026

    @edsiper
    Member

    @codex review

  4. chatgpt-codex-connector commented on Nov 20, 2026

    @chatgpt-codex-connector

    Summary

    • Updated YAML upstream loading to initialize the upstream pointer safely, require exactly one upstream group, and guard cleanup when no context was created. This prevents both uninitialized-pointer destruction and silent leaking/selection of the last group.
    • Added focused internal tests covering a valid single group, rejection of multiple groups, and rejection of files without upstream groups.
    • Registered the regression test whenever YAML support is enabled and added representative YAML fixtures.
    • Committed the changes as 01025c5 (upstream_ha: reject ambiguous YAML groups) with a DCO sign-off and created the follow-up pull request metadata titled “upstream_ha: reject ambiguous YAML groups safely.”

    Testing

    • ✅ cmake -S . -B build -DFLB_TESTS_RUNTIME=On -DFLB_TESTS_INTERNAL=On
    • ✅ cmake --build build -j8 --target flb-it-upstream_ha
    • ✅ ctest --test-dir build -R '^flb-it-upstream_ha$' --output-on-failure
    • ✅ valgrind --leak-check=full --error-exitcode=1 ./build/bin/flb-it-upstream_ha — all three tests passed, all allocations were freed, and Valgrind reported zero errors.
    • ✅ cmake --build build -j8 --target fluent-bit-bin
    • ✅ Live forward output initialization using the multiple-group fixture — startup rejected the file with expected exactly one upstream group, and Fluent Bit exited with status 255.
    • ✅ git diff --check
    • ⚠️ python .github/scripts/commit_prefix_check.py — could not run because GitPython is unavailable; installation with python3 -m pip install gitpython was blocked by the environment’s package-index proxy returning HTTP 403.

    View task →

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions