我知道printf(user_input)
很危险,但printf("%s", user_input)
呢?只要user_input
被NUL终止,这通常是安全的吗?
我知道printf(user_input)
很危险,但printf("%s", user_input)
呢?只要user_input
被NUL终止,这通常是安全的吗?
我知道
printf(user_input)
很危险,但printf("%s", user_input)
呢?这通常是安全的吗?
后者是通常为前者推荐的替代方案之一.它可以解析为the issue that makes printf(user_input)
particularly dangerous.
还有一些更一般的问题,比如如果user_input
不是指向以空结尾的字符串的指针,或者如果字符串包含从输出设备引发特殊行为的字符,或者如果标准输出流已经关闭,或者可能是其他事情,会发生什么.
我不确定"总体安全"是不是很好地描述了这一切,但也许这确实是你的意思.