<!DOCTYPE html>
<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-0 vector-toc-not-available vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-0 skin-theme-clientpref-os vector-sticky-header-enabled" lang="en" dir="ltr"><head>
    <meta charset="UTF-8">
    <title>Strsafe.h</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/png" href="./_res_/favicon.png">
    <link rel="canonical" href="https://en.wikipedia.org/wiki/Strsafe.h"> <link href="./_mw_/ext.cite.styles.css" rel="stylesheet" type="text/css">
    <link href="./_mw_/ext.wikimediamessages.styles.css" rel="stylesheet" type="text/css">
    <link href="./_mw_/skins.vector.icons.css" rel="stylesheet" type="text/css">
    <link href="./_mw_/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
    <link href="./_mw_/skins.vector.styles.css" rel="stylesheet" type="text/css">
    <meta name="ResourceLoaderDynamicStyles" content="">
    
    <link rel="stylesheet" type="text/css" href="./_mw_/site.styles.css">
    <link rel="stylesheet" type="text/css" href="./_mw_/noscript.css">
    <link rel="stylesheet" type="text/css" href="./_res_/footer.css">
    <link rel="stylesheet" type="text/css" href="./_res_/vector-2022.css">
  </head>
  <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Strsafe_h rootpage-Strsafe_h skin-vector-2022 action-view">
    <div class="mw-page-container">
      <div class="mw-page-container-inner">
        <div class="mw-content-container">
          <main id="content" class="mw-body">
            <header class="mw-body-header vector-page-titlebar">
              <h1 id="firstHeading" class="firstHeading mw-first-heading">strsafe.h</h1>
            </header>
            <a id="top"></a>
            <div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
              <div id="contentSub">
                <div id="mw-content-subtitle"></div>
              </div>
              <div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p><b>strsafe.h</b> is a non-standard C header file provided with the <a href="Windows_SDK" class="mw-redirect" title="Windows SDK">Windows SDK</a> starting with Windows XP Service Pack 2<sup id="cite_ref-MSDN1_1-0" class="reference"><a href="#cite_note-MSDN1-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> that provides safer buffer handling than that which is provided by the standard <a href="C_string_handling" title="C string handling">C string functions</a>, which are widely known to have security issues involving <a href="Buffer_overrun" class="mw-redirect" title="Buffer overrun">buffer overruns</a> when not used correctly.
</p>
<div class="mw-heading mw-heading2"><h2 id="Description">Description</h2></div>
<p>The functions included in strsafe.h replace standard C string handling and I/O functions including <code>printf</code>, <code>strlen</code>, <code>strcpy</code> and <code>strcat</code>.<sup id="cite_ref-Richter1_2-0" class="reference"><a href="#cite_note-Richter1-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> The strsafe functions require the length of the string in either characters or bytes as a parameter and if an operation would exceed the length of the destination buffer, the operation fails and the string is still terminated with a <a href="Null_character" title="Null character">null</a> in its final valid index so that using it in other library functions will not result in undefined behavior.<sup id="cite_ref-MSDN1_1-1" class="reference"><a href="#cite_note-MSDN1-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Richter1_2-1" class="reference"><a href="#cite_note-Richter1-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>  Independent security researchers have noted that security issues are still possible with the functions from strsafe.h if they are not passed the correct buffer length.<sup id="cite_ref-Daswani1_3-0" class="reference"><a href="#cite_note-Daswani1-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> The use of this library is recommended by the United States Department of Homeland Security.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1327269900">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}body.skin-vector-2022 .mw-parser-output .reflist-columns-2{column-width:27em}body.skin-vector-2022 .mw-parser-output .reflist-columns-3{column-width:22.5em}.mw-parser-output .references[data-mw-group=upper-alpha]{list-style-type:upper-alpha}.mw-parser-output .references[data-mw-group=upper-roman]{list-style-type:upper-roman}.mw-parser-output .references[data-mw-group=lower-alpha]{list-style-type:lower-alpha}.mw-parser-output .references[data-mw-group=lower-greek]{list-style-type:lower-greek}.mw-parser-output .references[data-mw-group=lower-roman]{list-style-type:lower-roman}.mw-parser-output div.reflist-liststyle-upper-alpha .references{list-style-type:upper-alpha}.mw-parser-output div.reflist-liststyle-upper-roman .references{list-style-type:upper-roman}.mw-parser-output div.reflist-liststyle-lower-alpha .references{list-style-type:lower-alpha}.mw-parser-output div.reflist-liststyle-lower-greek .references{list-style-type:lower-greek}.mw-parser-output div.reflist-liststyle-lower-roman .references{list-style-type:lower-roman}


/* end   https://en.wikipedia.org/ */
</style><div>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-MSDN1-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-MSDN1_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-MSDN1_1-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1333433106">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./_mw_/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./_mw_/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./_mw_/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./_mw_/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#bf3c2c)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#bf3c2c)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end   https://en.wikipedia.org/ */
</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms647466(v=vs.85).aspx">"About Strsafe.h (Windows)"</a>. 20 June 2022.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=About+Strsafe.h+%28Windows%29&amp;rft.date=2022-06-20&amp;rft_id=https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fwindows%2Fdesktop%2Fms647466%28v%3Dvs.85%29.aspx&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AStrsafe.h" class="Z3988"></span></span>
</li>
<li id="cite_note-Richter1-2"><span class="mw-cite-backlink">^ <a href="#cite_ref-Richter1_2-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Richter1_2-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFRichterNasarre" class="citation book cs1">Richter, Jeffrey; Nasarre, Christophe. <i>Windows via C/C++ Fifth Edition</i>. Microsoft Press. pp.&nbsp;<span class="nowrap">11–</span>32. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>9780735663770</bdi>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Windows+via+C%2FC%2B%2B+Fifth+Edition&amp;rft.pages=11-32&amp;rft.pub=Microsoft+Press&amp;rft.isbn=9780735663770&amp;rft.aulast=Richter&amp;rft.aufirst=Jeffrey&amp;rft.au=Nasarre%2C+Christophe&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AStrsafe.h" class="Z3988"></span></span>
</li>
<li id="cite_note-Daswani1-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-Daswani1_3-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFDaswaniKernKesavan" class="citation book cs1">Daswani, Neil; Kern, Christopher; Kesavan, Anita. <i>Foundations of Security: What Every Programmer Needs To Know</i>. Apress Media LLC. p.&nbsp;121. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>9781590597842</bdi>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Foundations+of+Security%3A+What+Every+Programmer+Needs+To+Know&amp;rft.pages=121&amp;rft.pub=Apress+Media+LLC&amp;rft.isbn=9781590597842&amp;rft.aulast=Daswani&amp;rft.aufirst=Neil&amp;rft.au=Kern%2C+Christopher&amp;rft.au=Kesavan%2C+Anita&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AStrsafe.h" class="Z3988"></span></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite id="CITEREFPlakosh,_Daniel" class="citation web cs1">Plakosh, Daniel. <a rel="nofollow" class="external text" href="https://buildsecurityin.us-cert.gov/articles/knowledge/coding-practices/strsafeh">"Strsafe.h | Build Security In"</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Strsafe.h+%7C+Build+Security+In&amp;rft.au=Plakosh%2C+Daniel&amp;rft_id=https%3A%2F%2Fbuildsecurityin.us-cert.gov%2Farticles%2Fknowledge%2Fcoding-practices%2Fstrsafeh&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AStrsafe.h" class="Z3988"></span></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms647466(v=vs.85).aspx">StrSafe.h documentation on MSDN</a></li></ul>
<p><br>
</p>
<style data-mw-deduplicate="TemplateStyles:r1271159938">
/* start https://en.wikipedia.org/ */


.mw-parser-output .asbox{position:relative;overflow:hidden}.mw-parser-output .asbox table{background:transparent}.mw-parser-output .asbox p{margin:0}.mw-parser-output .asbox p+p{margin-top:0.25em}.mw-parser-output .asbox-body{font-style:italic}.mw-parser-output .asbox-note{font-size:smaller}.mw-parser-output .asbox .navbar{position:absolute;top:-0.75em;right:1em;display:none}.mw-parser-output :not(p):not(.asbox)+style+.asbox,.mw-parser-output :not(p):not(.asbox)+link+.asbox{margin-top:3em}


/* end   https://en.wikipedia.org/ */
</style></div><!--htdig_noindex--><div><div class="zim-footer">
    This article is issued from <a class="external text" title="Last edited on 2024-11-20" href="https://en.wikipedia.org/wiki/?title=Strsafe.h&amp;oldid=1258650953">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
            </div>
          </main>
        </div>
      </div>
    </div>
     <script src="./_webp_/webpHandler.js"></script>
  

</body></html>