【资料整理】Security Features in the CRT

简介:

     本文简要整理了 MSDN 上关于 “Security Features in the CRT” 方面的内容。详细参考官网

     许多老旧的 CRT 函数都有更新且更加安全的后续版本。在安全版本存在的情况下,老旧版本都会被标识为废弃(deprecated)的状态,而安全版本都会以 "_s" 作为后缀。

注意:上面提到的废弃的状态不代表函数已经从 CRT 中被移除,而是表示不推荐使用。而安全版本同样不能阻止或者自行修正安全错误,而是其能够在这类错误发生时将错误进行捕获,因为这类函数会对发生的错误条件进行额外的检查。


【消除废弃警告】

  • 方法一:定义 _CRT_SECURE_NO_WARNINGS 宏,或者直接使用 #pragma warning( disable : xxxx ) 。这种方法只能起到眼不见心不烦的效果。
  • 方法二:使用 “安全模板重载(Secure Template Overloads,)”的方法。这种方法是通过重载的方式将老旧版本替换为新的安全版本来真正做到安全增强的,与此同时,老旧版本函数的名字仍旧可以照常使用。使用该方式时,需要定义宏 _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES。对于默认不存在“安全模板重载”的那些函数,需要自行手动更新你的代码来达到使用安全版本的效果。
  • 方法三:还有另外一种与安全无关的废弃警告的情况,是关于 POSIX 函数的。可以通过将 POSIX 函数名字更新到其对应的标准等价版本(一般是函数明前增加_)的方式消除警告;也可以通过定义宏 _CRT_NONSTDC_NO_WARNINGS 来屏蔽与 POSIX 函数废弃相关的警告。


PS:

已废弃的 CRT 函数可以参考:Deprecated CRT Functions

安全模板重载可以参考:Secure Template Overloads

目录
相关文章
《Automated-Testing-Of-Crypto-Software-Using-Differential-Fuzzing》电子版地址
Automated-Testing-Of-Crypto-Software-Using-Differential-Fuzzing
51 0
《Automated-Testing-Of-Crypto-Software-Using-Differential-Fuzzing》电子版地址
|
Android开发 iOS开发
iOS配置证书:Provisioning profile "xx_Distribution" doesn't include signing certificate "iPhone Developer
iOS配置证书:Provisioning profile "xx_Distribution" doesn't include signing certificate "iPhone Developer
456 0
|
安全 API
Developing Secure Applications for the Cloud
A discussion of security best practices for developers who are building cloud applications.
1579 0
|
网络协议 安全 应用服务中间件
WordPress with LEMP on Alibaba Cloud – Part 3 Configuring a Domain and Let's Encrypt SSL
Welcome to the third tutorial in this series about installing WordPress upon a highly performant server stack on an Alibaba ECS Cloud Instance.
2485 0