Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add(c,c++/3.4): 添加不可重入函数 #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion C,C++安全指南.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
+ [3.1 变量应确保线程安全性](#1.3.1)
+ [3.2 注意signal handler导致的条件竞争](#1.3.2)
+ [3.3 注意Time-of-check Time-of-use条件竞争](#1.3.3)
* [IV. 加密解密](#1.4)
+ [3.4 注意不可重入函数](#1.3.4)
[IV. 加密解密](#1.4)
+ [4.1 不得明文存储用户密码等敏感数据](#1.4.1)
+ [4.2 内存中的用户密码等敏感数据应该安全抹除](#1.4.2)
+ [4.3 rand() 类函数应正确初始化](#1.4.3)
Expand Down Expand Up @@ -1074,6 +1075,27 @@ TOCTOU难以修复,但是有以下缓解方案:

`中风险-逻辑问题`

<a id="1.3.4"></a>
#### 3.4 【建议】注意不可重入函数

不可重入函数:是指这样的一类函数,不可以在它还没有返回就再次被调用。例如printf,malloc,free等都是不可重入函数。函数不可重入大多数是因为在函数中引用了全局变量。例如,printf会引用全局变量stdout,malloc,free会引用全局的内存分配表。

不可重入函数,在多线程下可能无法达成预期结果,参考列表如下:

1. rand、srand
2. asctime、ctime、localtime、gmtime
3. getenv、getenv_s
4. strtok
5. strerror
6. setlocale
7. atomic_init
8. gethostbyaddr、gethostbyname
9. inet_ntoa

关联漏洞:

`中风险-逻辑问题`

<a id="1.4"></a>
### 4 加密解密

Expand Down