zoukankan      html  css  js  c++  java
  • 微软的secure string IO functions

    Findings during my work

    Wentao Sun.


    1. ZeroMemory on Windows is only a macro:
    fills block with zeros
    #if defined(OSMac_) || defined(OSLinux_)
        memset(pVoid, 
    0, length);
    #else
        ::ZeroMemory(pVoid, length);
    #endif
    最后用memset全部清零。
    在微软内部是用一个RtlZeroMemory的宏完成,而且有一些类似的宏。

    2
    wcscpy_s何以安全
    ?
    errno_t wcscpy_s(
       wchar_t 
    *strDestination,
       size_t numberOfElements,
       
    const wchar_t *strSource 
    );
    =============================
    Parameters
    strDestination 
    Location of destination 
    string buffer

    numberOfElements 
    Size of the destination string buffer.

    strSource 
    Null
    -terminated source string buffer.

    inline 
    void __cdecl wcscpy_s(_Out_cap_(_S1max) wchar_t *_S1, _In_ size_t _S1max, _In_z_ const wchar_t *_S2)
    {
        ATLMFC_CRT_ERRORCHECK(::wcscpy_s(_S1, _S1max, _S2));
    }

    _Check_return_wat_ _CRTIMP_ALTERNATIVE errno_t __cdecl wcscpy_s(_Out_z_cap_(_SizeInWords) wchar_t 
    * _Dst, _In_ rsize_t 

    _SizeInWords, _In_z_ 
    const wchar_t * _Src);

    第二个参数表示的是目标string的长度,而不是Number of characters to be copied

    比较:
    wchar_t 
    *wcsncpy(
       wchar_t 
    *strDest,
       
    const wchar_t *strSource,
       size_t count 
    );

    长度信息放在最后的一个参数中,表示的是准备copy到目标string中的src string中的字符数。



  • 相关阅读:
    JAVA基础 (三)反射 深入解析反射机制
    JAVA基础 (二)反射 深入解析反射机制
    JAVA注解引发的思考
    深入理解jsonp解决跨域访问
    设计模式之简单工厂模式
    设计模式之接口隔离原则
    设计模式之迪米特法则
    设计模式之依赖倒置原则
    设计模式之里氏替换原则
    设计模式之开放封闭原则
  • 原文地址:https://www.cnblogs.com/SunWentao/p/1298252.html
Copyright © 2011-2022 走看看