v1.7.19 added Undefined Behavior to cJSON_SetValuestring()
维护者通常 12 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 cJSON.c 第 425 行开始,检查 issue 所引用的现有测试用例。使用来自无关数组的指针重现该行为,并验证完成的更改不再依赖未定义的指针比较,同时保留 cJSON_SetValuestring() 的预期行为。
由索引模型根据 Issue 内容生成。
描述
This is incorrect C: https://github.com/DaveGamble/cJSON/blob/12c4bf1986c288950a3d06da757109a6aa1ece38/cJSON.c#L425
The C17 standard (6.5.8.5) says this about pointer comparisons:
When two pointers are compared, the result depends on the relative locations in the address space of the objects pointed to. If two pointers to object types both point to the same object, or both point one past the last element of the same array object, they compare equal. If the objects pointed to are members of the same aggregate object, pointers to structure members declared later compare greater than pointers to members declared earlier in the structure, and pointers to array elements with larger subscript values compare greater than pointers to elements of the same array with lower subscript values. All pointers to members of the same union object compare equal. If the expression P points to an element of an array object and the expression Q points to the last element of the same array object, the pointer expression Q+1 compares greater than P. In all other cases, the behavior is undefined.
In other words you can't legally determine whether or not two unrelated arrays overlap. It is only well-defined if those arrays belong to the same object. The current test case is free of UB because it happens to use pointers to addresses within the same array. That's not representative of real use.
- 主要语言
- C
- 星标
- 13k
- 派生
- 3.5k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
DaveGamble/cJSON 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
DaveGamble/cJSON#1106 ·
维护者通常 12 天内回复
-
Undefined-Behavior in function cJSON_SetNumberHelper可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
DaveGamble/cJSON#1100 · 1 个 reaction ·
维护者通常 12 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
DaveGamble/cJSON#1094 · 9 条评论 · 1 个 reaction ·
维护者通常 12 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
DaveGamble/cJSON#1093 ·
维护者通常 12 天内回复
-
Use-after-free in cJSONUtils_ApplyPatches when a patch removes the patch array可能已有人在做 @iliasabk 于 32 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
DaveGamble/cJSON#1082 ·
维护者通常 12 天内回复
相似的 Issue
-
v9.6.0: CMake incorrectly enforces presence of libevdev可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
IoTSDK
难度 2/5 1-3 小时 新手友好度 70/100
Azure/azure-iot-sdk-c#2776 ·
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
bug Component component: net
难度 2/5 1-3 小时 新手友好度 78/100
RT-Thread/rt-thread#11913 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
contiki-ng/contiki-ng#3289 ·
维护者通常 3 天内回复