Skip to content

lib: cfl: upgrade to v0.7.1#11795

Open
edsiper wants to merge 1 commit into
masterfrom
cfl-0.7.0
Open

lib: cfl: upgrade to v0.7.1#11795
edsiper wants to merge 1 commit into
masterfrom
cfl-0.7.0

Conversation

@edsiper
Copy link
Copy Markdown
Member

@edsiper edsiper commented May 12, 2026


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

    • Added atomic operations support for thread-safe 64-bit operations.
    • Added container ownership and management system for nested data structures.
    • Enhanced checksum validation with NULL input handling.
  • Bug Fixes

    • Hardened NULL pointer handling across core modules.
    • Added integer overflow protection in allocation and sizing operations.
    • Fixed JSON string escaping in variant and kvlist output.
    • Improved error handling and validation in array, kvlist, and variant operations.
  • Documentation

    • Expanded README with comprehensive interface documentation and usage examples.
    • Added repository guidelines and conventions in AGENTS.md.
  • Version

    • Bumped minor version to 0.7.1.
  • Tests

    • Added comprehensive test coverage for atomic operations and concurrency.
    • Added tests for cyclic reference detection and containment checks.
    • Enhanced edge-case testing for printing, sizing, and NULL inputs.
  • Chores

    • Updated GitHub Actions workflows to newer versions and expanded testing platforms.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

📝 Walkthrough

Walkthrough

Adds a public atomic API with platform backends, container containment/ownership to prevent cycles, pervasive NULL/overflow hardening, CI and documentation updates, CMake/test wiring, and extensive unit tests covering concurrency and edge cases.

Changes

CFL Core Library Enhancement

Layer / File(s) Summary
CI, docs, and repository guidelines
lib/cfl/.github/workflows/*, lib/cfl/AGENTS.md, lib/cfl/README.md
Workflow steps upgraded (checkout/upload/download action versions), Windows runner additions, Debian archive handling, README rewritten, and new AGENTS.md.
Version bump and CMake wiring
lib/cfl/CMakeLists.txt, lib/cfl/src/CMakeLists.txt
Bump CFL minor version and add CMake logic to select platform atomic backend and include new source files.
Public header hygiene and container/atomic contracts
lib/cfl/include/cfl/*.h
New cfl_atomic.h and cfl_container.h; added required standard includes and forward declarations across public headers.
Atomic API and cfl integration
lib/cfl/include/cfl/cfl_atomic.h, lib/cfl/src/cfl.c
Declare atomic initialize/compare-exchange/store/load and have cfl_init() return atomic initialization result.
Platform-specific atomic implementations
lib/cfl/src/cfl_atomic_*.c
Add GCC/Clang builtin wrappers, Clang-specific wrapper, generic pthread-based backend, and MSVC backend (intrinsics or locked path).
Container containment & ownership
lib/cfl/include/cfl/cfl_container.h, lib/cfl/src/cfl_container.c
Depth-limited recursive containment checks and APIs for claiming/adopting/moving/releasing variants to prevent cycles.
List, Array, KV, KV-list, Object hardening
lib/cfl/include/cfl/cfl_list.h, lib/cfl/include/cfl/cfl_array.h, lib/cfl/src/cfl_array.c, lib/cfl/src/cfl_kv.c, lib/cfl/src/cfl_kvlist.c, lib/cfl/src/cfl_object.c
Add CFL_TRUE/CFL_FALSE, owner/parent fields, NULL/INT_MAX checks, ownership-aware insert/cleanup, JSON-safe printing, and safer object adoption/reuse.
SDS, Variant, Utils, Checksum hardening
lib/cfl/src/cfl_sds.c, lib/cfl/src/cfl_variant.c, lib/cfl/src/cfl_utils.c, lib/cfl/src/cfl_checksum.c
Overflow-safe SDS growth/cat/printf, JSON escaping and non-finite double handling in variants, robust utils parsing, and checksum NULL guard.
Test infra and unit tests
lib/cfl/tests/CMakeLists.txt, lib/cfl/tests/*
Add atomic, checksum, headers tests; expand many suites for null inputs, cycle rejections, embedded NUL keys, escaping, non-finite doubles, self-append, write failures, and move/detach behaviors; CMake wires Threads and header-compile tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

ok-package-test

Suggested reviewers

  • cosmo0920
  • patrick-stephens
  • celalettin1286

Poem

🐰 With atoms safe and cycles caught,

headers neat and bounds all taught,
tests that race and prints that hide,
this little rabbit hops with pride.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'lib: cfl: upgrade to v0.7.1' accurately reflects the main change: upgrading the CFL library version from 0.7.0 to 0.7.1, as evidenced by the CMakeLists.txt version bump from 6 to 7.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cfl-0.7.0

Copy link
Copy Markdown

@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: c80159a0c0

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +24 to +25
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(PLATFORM_SPECIFIC_ATOMIC_MODULE cfl_atomic_gcc.c)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Link libatomic for GCC/Clang atomic builtins

When CFL is built with GCC/Clang on targets that cannot inline 64-bit __atomic_* operations (for example several 32-bit embedded architectures), this branch selects cfl_atomic_gcc.c/cfl_atomic_clang.c but never adds -latomic; the new implementation uses 64-bit __atomic_compare_exchange, __atomic_store_n, and __atomic_load_n, so executables that reference the new cfl_atomic_* API can fail at link time with unresolved __atomic_*_8 symbols. Please either probe/link atomic for these compiler branches or fall back to the mutex implementation when the builtins are not linkable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
lib/cfl/AGENTS.md (1)

1-77: ⚡ Quick win

Keep vendor bump PRs free of local process docs

Please avoid introducing lib/cfl/AGENTS.md in this dependency-upgrade PR. For Line 1 onward, this adds repo-local workflow policy inside vendored code and will likely increase drift/merge friction on future upstream CFL syncs. Consider moving this guidance to a top-level maintainer doc (or a separate PR) and keeping this PR limited to the v0.7.0 vendor update.

Based on learnings: "Prefer minimal patches that avoid unrelated formatting or refactoring churn" and "Do not mix unrelated code and documentation updates in one commit unless explicitly requested."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/cfl/AGENTS.md` around lines 1 - 77, Remove lib/cfl/AGENTS.md from this
vendor bump PR and keep the change focused on the v0.7.0 dependency update;
either relocate the guidance into a top-level maintainer document (e.g.,
MAINTAINERS.md) or open a separate PR for workflow/process docs, and ensure the
commit/PR only contains the vendor upgrade files referenced in this diff.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/cfl/src/cfl_sds.c`:
- Around line 227-229: The bounds check in cfl_sds.c for self-append slice
validation is off-by-one: replace the conditional that currently uses "if
(append_len - 1 > head->alloc - source_offset)" with a comparison using ">=" so
that when the source slice ends exactly at head->alloc it is rejected; update
the check around the variables append_len, source_offset and head->alloc in the
same block (the self-append slice validation) to use ">=" to prevent reading
s[head->alloc].

---

Nitpick comments:
In `@lib/cfl/AGENTS.md`:
- Around line 1-77: Remove lib/cfl/AGENTS.md from this vendor bump PR and keep
the change focused on the v0.7.0 dependency update; either relocate the guidance
into a top-level maintainer document (e.g., MAINTAINERS.md) or open a separate
PR for workflow/process docs, and ensure the commit/PR only contains the vendor
upgrade files referenced in this diff.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f9000ea8-4e50-4221-a359-e81fc01b0ac0

📥 Commits

Reviewing files that changed from the base of the PR and between 7299905 and c80159a.

📒 Files selected for processing (45)
  • lib/cfl/.github/workflows/build.yaml
  • lib/cfl/.github/workflows/lint.yaml
  • lib/cfl/.github/workflows/packages.yaml
  • lib/cfl/AGENTS.md
  • lib/cfl/CMakeLists.txt
  • lib/cfl/README.md
  • lib/cfl/include/cfl/cfl.h
  • lib/cfl/include/cfl/cfl_array.h
  • lib/cfl/include/cfl/cfl_atomic.h
  • lib/cfl/include/cfl/cfl_checksum.h
  • lib/cfl/include/cfl/cfl_container.h
  • lib/cfl/include/cfl/cfl_kv.h
  • lib/cfl/include/cfl/cfl_kvlist.h
  • lib/cfl/include/cfl/cfl_list.h
  • lib/cfl/include/cfl/cfl_object.h
  • lib/cfl/include/cfl/cfl_sds.h
  • lib/cfl/include/cfl/cfl_time.h
  • lib/cfl/include/cfl/cfl_utils.h
  • lib/cfl/include/cfl/cfl_variant.h
  • lib/cfl/src/CMakeLists.txt
  • lib/cfl/src/cfl.c
  • lib/cfl/src/cfl_array.c
  • lib/cfl/src/cfl_atomic_clang.c
  • lib/cfl/src/cfl_atomic_gcc.c
  • lib/cfl/src/cfl_atomic_generic.c
  • lib/cfl/src/cfl_atomic_msvc.c
  • lib/cfl/src/cfl_checksum.c
  • lib/cfl/src/cfl_container.c
  • lib/cfl/src/cfl_kv.c
  • lib/cfl/src/cfl_kvlist.c
  • lib/cfl/src/cfl_object.c
  • lib/cfl/src/cfl_sds.c
  • lib/cfl/src/cfl_utils.c
  • lib/cfl/src/cfl_variant.c
  • lib/cfl/tests/CMakeLists.txt
  • lib/cfl/tests/array.c
  • lib/cfl/tests/atomic_operations.c
  • lib/cfl/tests/checksum.c
  • lib/cfl/tests/headers.c
  • lib/cfl/tests/kv.c
  • lib/cfl/tests/kvlist.c
  • lib/cfl/tests/object.c
  • lib/cfl/tests/sds.c
  • lib/cfl/tests/utils.c
  • lib/cfl/tests/variant.c

Comment thread lib/cfl/src/cfl_sds.c Outdated
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper edsiper changed the title lib: cfl: upgrade to v0.7.0 lib: cfl: upgrade to v0.7.1 May 13, 2026
Copy link
Copy Markdown

@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: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/cfl/CMakeLists.txt`:
- Around line 6-10: The CMake version variables currently set
(CFL_VERSION_MAJOR, CFL_VERSION_MINOR, CFL_VERSION_PATCH) compute
CFL_VERSION_STR as "0.7.1" which mismatches the PR text; either set
CFL_VERSION_PATCH to 0 so CFL_VERSION_STR becomes "0.7.0" or update the PR
title/description to "v0.7.1" for consistency—locate and edit the entries
CFL_VERSION_PATCH and CFL_VERSION_STR in lib/cfl/CMakeLists.txt (or update PR
metadata) so package naming and release artifacts match the declared version.

In `@lib/cfl/src/cfl_container.c`:
- Around line 475-519: The function cfl_container_move_variant_to_array must
reject variants already owned by another container: check variant->owned (and
return -1) early—before calling claim_variant_container() and before modifying
any parent pointers; do the same change in the sibling helper (the
move-to-kvlist function, e.g. cfl_container_move_variant_to_kvlist) so both
helpers fail fast on variant->owned to prevent double-ownership/double-free/UAF.

In `@lib/cfl/src/CMakeLists.txt`:
- Around line 65-71: The Windows atomic fallback currently forces
PLATFORM_SPECIFIC_ATOMIC_MODULE to cfl_atomic_msvc.c on CFL_SYSTEM_WINDOWS which
uses MSVC-only intrinsics (e.g., _InterlockedCompareExchange64) and fails for
MinGW/Clang/GCC; update the CMake logic to only select cfl_atomic_msvc.c when
the compiler is MSVC (e.g., CMAKE_C_COMPILER_ID MATCHES "MSVC") and otherwise
fall back to cfl_atomic_generic.c or set CFL_ATOMIC_NEEDS_THREADS On so non‑MSVC
Windows builds use the compiler-agnostic implementation; modify the branch
around CFL_SYSTEM_WINDOWS/CFL_ATOMIC_BUILTINS_LINK_WITH_LIBATOMIC to gate
PLATFORM_SPECIFIC_ATOMIC_MODULE selection by the compiler ID.

In `@lib/cfl/tests/kvlist.c`:
- Around line 1254-1267: The test must return immediately on setup failures
instead of proceeding because TEST_CHECK doesn't abort; after creating the list
(cfl_kvlist_create), after inserting the string (cfl_kvlist_insert_string),
after creating the tmp file (tmpfile) and after printing (cfl_kvlist_print)
check the return values and if any indicate failure, free any allocated
resources (e.g., destroy the list) and return from the test function so
subsequent calls (like compare which uses fp) cannot dereference NULL or invalid
handles; specifically add early returns when list == NULL, ret != 0 for
cfl_kvlist_insert_string, fp == NULL after tmpfile, and ret <= 0 for
cfl_kvlist_print, cleaning up as needed before returning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e2aef14a-3075-4d16-8e7a-64b6e00395d9

📥 Commits

Reviewing files that changed from the base of the PR and between c80159a and 427d908.

📒 Files selected for processing (45)
  • lib/cfl/.github/workflows/build.yaml
  • lib/cfl/.github/workflows/lint.yaml
  • lib/cfl/.github/workflows/packages.yaml
  • lib/cfl/AGENTS.md
  • lib/cfl/CMakeLists.txt
  • lib/cfl/README.md
  • lib/cfl/include/cfl/cfl.h
  • lib/cfl/include/cfl/cfl_array.h
  • lib/cfl/include/cfl/cfl_atomic.h
  • lib/cfl/include/cfl/cfl_checksum.h
  • lib/cfl/include/cfl/cfl_container.h
  • lib/cfl/include/cfl/cfl_kv.h
  • lib/cfl/include/cfl/cfl_kvlist.h
  • lib/cfl/include/cfl/cfl_list.h
  • lib/cfl/include/cfl/cfl_object.h
  • lib/cfl/include/cfl/cfl_sds.h
  • lib/cfl/include/cfl/cfl_time.h
  • lib/cfl/include/cfl/cfl_utils.h
  • lib/cfl/include/cfl/cfl_variant.h
  • lib/cfl/src/CMakeLists.txt
  • lib/cfl/src/cfl.c
  • lib/cfl/src/cfl_array.c
  • lib/cfl/src/cfl_atomic_clang.c
  • lib/cfl/src/cfl_atomic_gcc.c
  • lib/cfl/src/cfl_atomic_generic.c
  • lib/cfl/src/cfl_atomic_msvc.c
  • lib/cfl/src/cfl_checksum.c
  • lib/cfl/src/cfl_container.c
  • lib/cfl/src/cfl_kv.c
  • lib/cfl/src/cfl_kvlist.c
  • lib/cfl/src/cfl_object.c
  • lib/cfl/src/cfl_sds.c
  • lib/cfl/src/cfl_utils.c
  • lib/cfl/src/cfl_variant.c
  • lib/cfl/tests/CMakeLists.txt
  • lib/cfl/tests/array.c
  • lib/cfl/tests/atomic_operations.c
  • lib/cfl/tests/checksum.c
  • lib/cfl/tests/headers.c
  • lib/cfl/tests/kv.c
  • lib/cfl/tests/kvlist.c
  • lib/cfl/tests/object.c
  • lib/cfl/tests/sds.c
  • lib/cfl/tests/utils.c
  • lib/cfl/tests/variant.c
✅ Files skipped from review due to trivial changes (10)
  • lib/cfl/.github/workflows/lint.yaml
  • lib/cfl/include/cfl/cfl_utils.h
  • lib/cfl/include/cfl/cfl_object.h
  • lib/cfl/include/cfl/cfl_time.h
  • lib/cfl/include/cfl/cfl_kv.h
  • lib/cfl/include/cfl/cfl_checksum.h
  • lib/cfl/include/cfl/cfl_atomic.h
  • lib/cfl/AGENTS.md
  • lib/cfl/README.md
  • lib/cfl/include/cfl/cfl.h
🚧 Files skipped from review as they are similar to previous changes (20)
  • lib/cfl/tests/headers.c
  • lib/cfl/src/cfl_atomic_gcc.c
  • lib/cfl/src/cfl_checksum.c
  • lib/cfl/tests/kv.c
  • lib/cfl/tests/checksum.c
  • lib/cfl/include/cfl/cfl_sds.h
  • lib/cfl/src/cfl.c
  • lib/cfl/src/cfl_atomic_clang.c
  • lib/cfl/include/cfl/cfl_list.h
  • lib/cfl/tests/array.c
  • lib/cfl/.github/workflows/packages.yaml
  • lib/cfl/tests/object.c
  • lib/cfl/src/cfl_atomic_msvc.c
  • lib/cfl/src/cfl_atomic_generic.c
  • lib/cfl/src/cfl_sds.c
  • lib/cfl/src/cfl_kv.c
  • lib/cfl/tests/CMakeLists.txt
  • lib/cfl/.github/workflows/build.yaml
  • lib/cfl/tests/atomic_operations.c
  • lib/cfl/src/cfl_kvlist.c

Comment thread lib/cfl/CMakeLists.txt
Comment on lines 6 to 10
# C Floppy Version
set(CFL_VERSION_MAJOR 0)
set(CFL_VERSION_MINOR 6)
set(CFL_VERSION_MINOR 7)
set(CFL_VERSION_PATCH 1)
set(CFL_VERSION_STR "${CFL_VERSION_MAJOR}.${CFL_VERSION_MINOR}.${CFL_VERSION_PATCH}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

What is the latest version of the cfl library (C Floppy library)?

💡 Result:

The “C Floppy library” (cfl) appears to refer to the fluent/cfl C-flavored library. Its latest released version is v0.6.1 (marked “Latest” and dated May 22, 2025 on the repository page). [1] Note: there are other unrelated software projects abbreviated “cfl” (e.g., “Causal Feature Learning”, “Compressed File Library”, etc.), so the name is ambiguous; the fluent/cfl repository is the only one in the sources explicitly describing “c:\ floppy” as “CFL”. [2]

Citations:


Update PR title and description or adjust version numbers for consistency.

The version configured in the code (0.7.1) does not match the PR title and description, which state "upgrade to v0.7.0." The computed version string will be "0.7.1", which flows through to package naming and release artifacts. Either update CFL_VERSION_PATCH to 0 (to match the stated v0.7.0), or update the PR title/description to "v0.7.1" for consistency.

Note: The upstream cfl library's latest released version is v0.6.1; the 0.7.x version does not yet have an official release.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/cfl/CMakeLists.txt` around lines 6 - 10, The CMake version variables
currently set (CFL_VERSION_MAJOR, CFL_VERSION_MINOR, CFL_VERSION_PATCH) compute
CFL_VERSION_STR as "0.7.1" which mismatches the PR text; either set
CFL_VERSION_PATCH to 0 so CFL_VERSION_STR becomes "0.7.0" or update the PR
title/description to "v0.7.1" for consistency—locate and edit the entries
CFL_VERSION_PATCH and CFL_VERSION_STR in lib/cfl/CMakeLists.txt (or update PR
metadata) so package naming and release artifacts match the declared version.

Comment on lines +475 to +519
int cfl_container_move_variant_to_array(struct cfl_array *array,
struct cfl_variant *variant)
{
struct cfl_array *child_array;
struct cfl_kvlist *child_kvlist;

if (array == NULL || variant == NULL) {
return -1;
}

if (variant->type == CFL_VARIANT_ARRAY) {
child_array = variant->data.as_array;

if (child_array != NULL &&
parent_chain_contains_array(array, NULL, child_array)) {
return -1;
}
}
else if (variant->type == CFL_VARIANT_KVLIST) {
child_kvlist = variant->data.as_kvlist;

if (child_kvlist != NULL &&
parent_chain_contains_kvlist(array, NULL, child_kvlist)) {
return -1;
}
}

if (claim_variant_container(variant) != 0) {
return -1;
}

if (variant->type == CFL_VARIANT_ARRAY &&
variant->data.as_array != NULL) {
variant->data.as_array->parent_array = array;
variant->data.as_array->parent_kvlist = NULL;
}
else if (variant->type == CFL_VARIANT_KVLIST &&
variant->data.as_kvlist != NULL) {
variant->data.as_kvlist->parent_array = array;
variant->data.as_kvlist->parent_kvlist = NULL;
}

variant->owned = CFL_TRUE;

return 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Reject already-owned variants before reparenting.

Both move helpers can accept a variant that is already stored in another container. That lets two parents own and later destroy the same struct cfl_variant *, which is a double-free/UAF path. Fail fast on variant->owned before claiming or updating parent pointers.

Suggested fix
 int cfl_container_move_variant_to_array(struct cfl_array *array,
                                         struct cfl_variant *variant)
 {
     struct cfl_array *child_array;
     struct cfl_kvlist *child_kvlist;
 
     if (array == NULL || variant == NULL) {
         return -1;
     }
+    if (variant->owned) {
+        return -1;
+    }
 
     if (variant->type == CFL_VARIANT_ARRAY) {
         child_array = variant->data.as_array;
@@
 int cfl_container_move_variant_to_kvlist(struct cfl_kvlist *kvlist,
                                          struct cfl_variant *variant)
 {
     struct cfl_array *child_array;
     struct cfl_kvlist *child_kvlist;
 
     if (kvlist == NULL || variant == NULL) {
         return -1;
     }
+    if (variant->owned) {
+        return -1;
+    }
 
     if (variant->type == CFL_VARIANT_ARRAY) {
         child_array = variant->data.as_array;

Also applies to: 522-566

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/cfl/src/cfl_container.c` around lines 475 - 519, The function
cfl_container_move_variant_to_array must reject variants already owned by
another container: check variant->owned (and return -1) early—before calling
claim_variant_container() and before modifying any parent pointers; do the same
change in the sibling helper (the move-to-kvlist function, e.g.
cfl_container_move_variant_to_kvlist) so both helpers fail fast on
variant->owned to prevent double-ownership/double-free/UAF.

Comment on lines +65 to +71
if(CFL_ATOMIC_BUILTINS_LINK_WITH_LIBATOMIC)
set(CFL_ATOMIC_NEEDS_LIBATOMIC On)
elseif(CFL_SYSTEM_WINDOWS)
set(PLATFORM_SPECIFIC_ATOMIC_MODULE cfl_atomic_msvc.c)
else()
set(PLATFORM_SPECIFIC_ATOMIC_MODULE cfl_atomic_generic.c)
set(CFL_ATOMIC_NEEDS_THREADS On)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -e

echo "== Atomic fallback branch =="
sed -n '51,74p' lib/cfl/src/CMakeLists.txt

echo
echo "== cfl_atomic_msvc.c (inspect for MSVC-only intrinsics/guards) =="
sed -n '1,200p' lib/cfl/src/cfl_atomic_msvc.c

echo
echo "== Other atomic backends present =="
fd '^cfl_atomic_.*\.c$' lib/cfl/src

Repository: fluent/fluent-bit

Length of output: 5147


Fix Windows atomic fallback to support non-MSVC compilers.

The 64-bit path in cfl_atomic_msvc.c uses MSVC intrinsics (_InterlockedCompareExchange64, _InterlockedExchange64, _InterlockedOr64), which are unavailable on MinGW and other non-MSVC Windows toolchains. If the builtin probe fails on Windows with GCC/Clang, this fallback will fail to compile.

Either:

  1. Gate the cfl_atomic_msvc.c backend on a compiler check (e.g., CMAKE_C_COMPILER_ID MATCHES "MSVC"), or
  2. Reimplement the 64-bit atomic operations using compiler-agnostic Windows APIs (critical section or synchronization APIs) like the 32-bit path does.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/cfl/src/CMakeLists.txt` around lines 65 - 71, The Windows atomic fallback
currently forces PLATFORM_SPECIFIC_ATOMIC_MODULE to cfl_atomic_msvc.c on
CFL_SYSTEM_WINDOWS which uses MSVC-only intrinsics (e.g.,
_InterlockedCompareExchange64) and fails for MinGW/Clang/GCC; update the CMake
logic to only select cfl_atomic_msvc.c when the compiler is MSVC (e.g.,
CMAKE_C_COMPILER_ID MATCHES "MSVC") and otherwise fall back to
cfl_atomic_generic.c or set CFL_ATOMIC_NEEDS_THREADS On so non‑MSVC Windows
builds use the compiler-agnostic implementation; modify the branch around
CFL_SYSTEM_WINDOWS/CFL_ATOMIC_BUILTINS_LINK_WITH_LIBATOMIC to gate
PLATFORM_SPECIFIC_ATOMIC_MODULE selection by the compiler ID.

Comment thread lib/cfl/tests/kvlist.c
Comment on lines +1254 to +1267
list = cfl_kvlist_create();
TEST_CHECK(list != NULL);

ret = cfl_kvlist_insert_string(list, "a\"b\n", "v\n");
TEST_CHECK(ret == 0);

fp = tmpfile();
TEST_CHECK(fp != NULL);

ret = cfl_kvlist_print(fp, list);
TEST_CHECK(ret > 0);

ret = compare(fp, "{\"a\\\"b\\n\":\"v\\n\"}");
TEST_CHECK(ret == 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Return immediately after setup failures in this test.

TEST_CHECK does not abort. If tmpfile() fails here, compare(fp, ...) dereferences fp through fseek() and the test can crash instead of reporting a normal failure.

Suggested fix
     list = cfl_kvlist_create();
-    TEST_CHECK(list != NULL);
+    if (!TEST_CHECK(list != NULL)) {
+        return;
+    }

     ret = cfl_kvlist_insert_string(list, "a\"b\n", "v\n");
     TEST_CHECK(ret == 0);

     fp = tmpfile();
-    TEST_CHECK(fp != NULL);
+    if (!TEST_CHECK(fp != NULL)) {
+        cfl_kvlist_destroy(list);
+        return;
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/cfl/tests/kvlist.c` around lines 1254 - 1267, The test must return
immediately on setup failures instead of proceeding because TEST_CHECK doesn't
abort; after creating the list (cfl_kvlist_create), after inserting the string
(cfl_kvlist_insert_string), after creating the tmp file (tmpfile) and after
printing (cfl_kvlist_print) check the return values and if any indicate failure,
free any allocated resources (e.g., destroy the list) and return from the test
function so subsequent calls (like compare which uses fp) cannot dereference
NULL or invalid handles; specifically add early returns when list == NULL, ret
!= 0 for cfl_kvlist_insert_string, fp == NULL after tmpfile, and ret <= 0 for
cfl_kvlist_print, cleaning up as needed before returning.

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.

1 participant