Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Vulnerability] Atomic Rollback Failure in cJSONUtils_ApplyPatchesCaseSensitive leads to "Dirty State" on error

未关闭
#997 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 12 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
c
领域
backend

调研方向

首先阅读 cJSON_Utils.c,尤其是 cJSONUtils_ApplyPatchesCaseSensitive 及其内部函数 apply_patch。复现 issue 中先成功后失败的 patch 序列,然后跟踪发生错误后之前的修改如何继续保留。完成的标准是:失败的 patch 序列使原始 JSON 对象保持不变,或提供所述的 rollback 机制。

由索引模型根据 Issue 内容生成。

描述

Clear and concise description of the bug:
The function cJSONUtils_ApplyPatchesCaseSensitive lacks transactional atomicity when applying a sequence of JSON patches. It utilizes an "in-place modification" strategy without creating a snapshot or backup of the original object.
If an error occurs in the middle of a patch sequence (e.g., a remove operation on a non-existent path), the function immediately returns an error code but does not revert the patches that were successfully applied earlier in the same call. This results in the target JSON object being left in an unpredictable "dirty" or partially modified state, which can be exploited for security bypasses (like privilege escalation) or cause data inconsistency.

Steps to reproduce the bug :
1.Prepare a base JSON object:

{ "status": "locked", "count": 1 }

2.Construct a malicious patch sequence with a "success-then-fail" logic:

[
  { "op": "replace", "path": "/status", "value": "unlocked" },
  { "op": "remove", "path": "/non_existent_path_to_force_error" }
]

3.Apply the patches using cJSONUtils_ApplyPatchesCaseSensitive
4.Observe the result: The function returns a non-zero error code (e.g., 13), but the status field in the original object has already been changed to "unlocked".

Expected behavior:
If cJSONUtils_ApplyPatchesCaseSensitive fails to apply the entire patch set, it should ensure the original JSON object remains unchanged (Atomicity), or provide a mechanism to roll back to the initial state.

Observed behavior:
The function returns an error, but the memory state of the object is permanently altered by the preceding successful patch operations.
Expected State after failure: {"status": "locked", "count": 1}
Actual Dirty State: {"status": "unlocked", "count": 1}

Platform(s) (compiler version, operating system version, CPU) on which the bug was observed:
OS: Ubuntu 20.04 LTS
Compiler: GCC 9.4.0
Build System: CMake 3.16.3

cJSON release(s), commit(s), or branch(es) in which the bug was observed:
cJSON(main branch)
Affected File: cJSON_Utils.c
Affected Function: cJSONUtils_ApplyPatchesCaseSensitive and internal apply_patch.

主要语言
C
星标
13k
派生
3.5k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DaveGamble/cJSON 的其他 Issue

查看 DaveGamble/cJSON 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。