`CON34-C`: Implementation seems to check incorrect aspects of thread storage duration objects

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

已经有一个关联 PR 被合并了。

  • #778 来自 @lcartey —— 已合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
c
领域
tooling

调研方向

从 CON34-C 的实现及其针对 tss_t 值的现有验证开始,然后将其与此 issue 中的符合要求和不符合要求的示例进行比较。当预期的 thread-storage 违规被报告,且无关的未初始化值案例不被归因于 CON34-C 时,修改即完成;使用该规则可用的测试进行验证。

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

描述

false positive/false negative Standard-CERT-C
Affected rules
  • CON34-C
Description

The documentation seems to describe the risk of passing a tss_t into a thread. The risk here is that the new thread will have no value.

In the "compliant" case it says the appropriate fix is to use tss_get() to get the value in the current thread, then pass that value into the new thread.

In our implementation, we check that any tss_t values are definitely given a value before retrieved and passed into a thread creation statement. This is not the intention of the rule, adds additional implementation complexity, and reveals no violations in MRVA.

Example
tss_t key;
void f1() {
  // Should be marked non-compliant: new thread has no value for tss_get(key)
  // Currently not reported
  thrd_create(..., &key);
}

void f2() {
  // While the following code is suspect, it is NOT the intention of the rule is not to disallow this:
  tss_t localkey;
  tss_set(localkey, malloc(...));
  void* v = tss_get(localkey);
  thrd_create(..., v);

  // The fact that v is uninitialized has nothing to do with threads. For instance, this is also erroneous:
  printf("%d", *v);

  // Further, the above code has nothing to do with thread storage duration, and isn't necessarily invalid:
  static void *shared_buf = malloc(...);
  thrd_create(..., shared_buf); // Reasonable pattern
}
主要语言
CodeQL
星标
227
派生
82
平均合并
6 天 7 小时
30 天内合并 PR
9

贡献指南

打开贡献指南

从这里开始

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

github/codeql-coding-standards 的其他 Issue

查看 github/codeql-coding-standards 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

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