格式化函数参数过多¶
ID: cpp/too-many-format-arguments
Kind: problem
Security severity:
Severity: recommendation
Precision: high
Tags:
- reliability
- correctness
Query suites:
- cpp-security-and-quality.qls
对 printf
函数或相关函数的每次调用都应包含格式定义的参数数量。从安全角度来看,将比所需更多的参数传递给函数通常是无害的,但表明可能需要不同的行为。
建议¶
查看突出显示的函数调用所期望的格式和参数。更新格式或参数,以便将预期数量的参数传递给函数。
示例¶
void log_connection_attempt(const char *user_name, char char *ip_address) {
// This does not print `ip_address`.
fprintf(stderr, "Connection attempted by '%s'\n", user_name, ip_address);
}
参考¶
CERT C 编码标准:FIO47-C. 使用有效的格式字符串.
Microsoft C 运行时库参考:printf, wprintf.