plengauer/Thoth

[MegaLinter][valid] C code: missing NULL checks after malloc/calloc, sprintf usage, and needs a clang-format pass

已关闭

#3,836 创建于 2026年7月24日

 (1 条评论) (1 个反应) (2 位负责人)Shell (13 个派生)auto 404
buggood first issue

仓库指标

星标
 (160 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

From the 2026-07-24 Analyze run, covering the only 2 C files in the repo: actions/instrument/job/forward.c and src/usr/share/opentelemetry_shell/agent.instrumentation.http/agent.injection.http_header.c. All classified as valid findings (bucket 1).

cppcheck: real robustness bugs (2 findings)

Missing NULL checks after allocation, each with a genuine null-pointer-dereference path if the allocation fails:

  • forward.c:19original_command = malloc(total_length) (line 18) not checked before use at line 19
  • forward.c:39,47,49new_argv = calloc(...) (line 37) not checked before use
  • agent.injection.http_header.c:238-242my_key = calloc(...) (line 236) and my_value = calloc(...) (line 237) not checked before use

cpplint: mostly real, two rules worth reconsidering

Findings across both files: sprintfsnprintf (3 occurrences, genuine buffer-overflow-avoidance suggestion — the C equivalent of a real security nit), line length > 80 chars (~15 occurrences), trailing whitespace, comment spacing, if-body-on-separate-line style.

Two sub-rules are Google-C++-style-guide-specific and may not be worth keeping for this project specifically:

  • legal/copyright — wants a // Copyright [year] <Owner> header in every file; this repo already has a top-level LICENSE, so per-file headers may be considered redundant
  • readability/todo — wants // TODO(username): ... format

If you don't want those two, cpplint supports C_CPPLINT_ARGUMENTS: ["--filter=-legal/copyright,-readability/todo"] in .mega-linter.yml. Left as-is for now since it's a minor call either way.

clang-format: needs a pass (190 findings, both files)

Every line in both files is flagged — reads like clang-format has simply never been run on this code. clang-format -i actions/instrument/job/forward.c src/usr/share/opentelemetry_shell/agent.instrumentation.http/agent.injection.http_header.c should resolve the bulk of it in one shot.

贡献者指南