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中的字符数。



  • 相关阅读:
    linux 内核升级4.19
    监管对保险页面的要求
    软件测试-测试可交付成果
    软件测试架构思想
    dockerfile
    转载:.NET Core 图片操作在 Linux/Docker 下的坑
    docker build速度过慢问题
    .net 5 发布到 docker 或 docker 镜像方法
    Centos 安装 docker 教程
    DQL、DML、DDL、DCL全名是啥?
  • 原文地址:https://www.cnblogs.com/SunWentao/p/1298252.html
Copyright © 2011-2022 走看看