禁用 API 使用方式:函式名稱 不安全,且已標示為已被取代。
此警告表示正在使用一個已被禁止的函式,而它已有一個更強固或更安全的替代方案。
備註
此錯誤涵蓋的所有禁用函式清單、為何禁止它們,以及建議的取代專案可在下列範例之後找到。
程式代碼分析名稱:BANNED_API_USAGE(禁止的API使用)
例
下列程式代碼會產生此警告:
void example_func(PSTR src)
{
char dst[100];
strcpy(dst, src);
}
此問題源於使用不安全的函式 strcpy。
strcpy 不會檢查目的地緩衝區是否夠大,足以容納源數據。
若要修正此問題,我們可以使用 strcpy_s,C++11 更安全地取代此函式。
strcpy_s 具有第三個參數(目的地緩衝區的大小),以確保只會複製許多位元組。 例如,下列程式代碼更安全:
void example_func(PSTR src)
{
char dst[100];
strcpy_s(dst, sizeof(dst), src);
}
禁用函式
注意:此列表正在積極更新和改善
| 禁用 API | 替換件 | 理由/附注 |
|---|---|---|
_fstrcat |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
舊版 16 位遠指標實作 |
_fstrcpy |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
傳統 16 位元遠端指針實作 |
_fstrncat |
StringCbCatN、StringCbCatNEx、StringCchCatN、StringCchCatNEx |
舊版 16 位遠指標實作 |
_fstrncpy |
strncpy、wcsncpy |
舊版 16 位遠指標實作 |
_ftccat |
strcat、wcscat |
舊版 16 位遠指標實作 |
_ftccpy |
strcpy、wcscpy |
舊版 16 位遠指標實作 |
_ftcscat |
strcat、wcscat |
舊版 16 位遠指標實作 |
_ftcscpy |
strcpy、wcscpy |
舊版 16 位遠指標實作 |
_getts |
StringCbGets、StringCbGetsEx、StringCchGets、StringCchGetsEx、gets_s |
數據沒有大小限制 |
_gettws |
gets_s |
數據沒有大小限制 |
_getws |
_getws_s |
數據沒有大小限制 |
_mbccat |
strcat_s、StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx、strlcat |
數據沒有大小限制 |
_makepath |
_makepath_s |
數據沒有大小限制 |
_mbscat |
_mbscat_s |
|
_snprintf |
_snprintf_s |
不會以 NULL 終止 |
_sntprintf |
StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintfEx、StringCchPrintf、StringCchPrintfEx |
不會以 NULL 終止 |
_sntscanf |
_snscanf_s |
沒有最大長度 |
_snwprintf |
_snwprintf_s、StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintfEx、StringCchPrintf、StringCchPrintfEx |
不會以 NULL 終止 |
_splitpath |
_splitpath_s |
沒有邊界檢查 |
_stprintf |
StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintfEx、StringCchPrintf、StringCchPrintfEx |
有限的錯誤偵測 |
_stscanf |
sscanf_s (需要格式字串變更) |
沒有邊界檢查 |
_tccat |
strcat_s、StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx、strlcat |
沒有邊界檢查 |
_tccpy |
strcpy_s、StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx、strlcpy |
沒有邊界檢查 |
_tcscat |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
_tcscpy |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
有限的錯誤偵測 |
_tcsncat |
StringCbLength、StringCchLength、UnalignedStringCbLength、UnalignedStringCchLength |
沒有最大長度 |
_tcsncpy |
StringCbCopyN、StringCbCopyNEx、StringCchCopyN、StringCchCopyNEx |
有限的錯誤偵測 |
_tmakepath |
_makepath_s |
沒有邊界檢查 |
_tscanf |
scanf_s |
對輸出沒有邊界檢查 |
_tsplitpath |
splitpath_s、wsplitpath_s |
沒有界限檢查 |
_vsnprintf |
_vsnprintf_s、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
有限的錯誤偵測 |
_vsntprintf |
StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
有限的錯誤偵測 |
_vsnwprintf |
_vsnwprintf_s、StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx |
有限的錯誤偵測 |
_vstprintf |
StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrinfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
沒有最大長度 |
_wmakepath |
_wmakepath_s |
沒有界限檢查 |
_wsplitpath |
_wsplitpath_s |
沒有邊界檢查 |
OemToCharW |
WideCharToMultiByte |
沒有邊界檢查 |
StrCat |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
StrCatA |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
StrCatBuff |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
沒有 NULL 終止符 |
StrCatBuffA |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
無「NULL」結尾 |
StrCatBuffW |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
無 NULL 終止符 |
StrCatChainW |
StringCbCatEx、StringCbCatNEx、StringCchCatEx、StringCchCatNEx |
未使用 NULL 終止符 |
StrCatN |
StringCbCat、StringCbCatEx、StringCbCatN、StringCbCatNEx、StringCchCat、StringCchCatEx、StringCchCatN、StringCchCatNEx |
沒有界限檢查 |
StrCatNA |
StringCbCat、StringCbCatEx、StringCbCatN、StringCbCatNEx、StringCchCat、StringCchCatEx、StringCchCatN、StringCchCatNEx |
沒有邊界檢查 |
StrCatNW |
StringCbCat、StringCbCatEx、StringCbCatN、StringCbCatNEx、StringCchCat、StringCchCatEx、StringCchCatN、StringCchCatNEx |
沒有界限檢查 |
StrCatW |
StringCbCat、StringCbCatEx、StringCbCatN、StringCbCatNEx、StringCchCat、StringCchCatEx、StringCchCatN、StringCchCatNEx |
沒有邊界檢查 |
StrCpy |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
沒有邊界檢查 |
StrCpyA |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
沒有界限檢查 |
StrCpyN |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
不會以 NULL 終止 |
StrCpyNA |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
不會以 NULL 終止 |
StrCpyNW |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
有限的錯誤檢查 |
strcpyW |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
沒有界限檢查 |
StrCpyW |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
沒有界限檢查 |
StrNCat |
StringCbCatN、StringCbCatNEx、StringCchCatN、StringCchCatNEx |
有限的錯誤偵測 |
StrNCatA |
StringCbCatN、StringCbCatNEx、StringCchCatN、StringCchCatNEx |
有限的錯誤偵測 |
StrNCatW |
StringCbCatN、StringCbCatNEx、StringCchCatN、StringCchCatNEx |
有限的錯誤偵測 |
StrNCpy |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
不會以 NULL 終止 |
StrNCpyA |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
不會使用 NULL 作結尾 |
StrNCpyW |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
不會以 NULL 終止 |
gets |
gets_s、fgets、StringCbGets、StringCbGetsEx、StringCchGets、StringCchGetsEx |
有限的錯誤偵測;由 C11 標準取代 |
lstrcat |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
lstrcatA |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
lstrcatn |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
lstrcatnA |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
lstrcatnW |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
lstrcatW |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
lstrcpy |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
邊界檢查未實行 |
lstrcpyA |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
沒有邊界檢查 |
lstrcpyn |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
有限的錯誤偵測 |
lstrcpynA |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
有限的錯誤偵測 |
lstrcpynW |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
沒有邊界檢查 |
lstrcpyW |
StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx |
沒有界限檢查 |
snscanf |
sscanf_s |
沒有界限檢查 |
snwscanf |
swscanf_s |
沒有邊界檢查 |
sprintf |
sprintf_s |
有限的錯誤偵測 |
sprintfA |
sprintf_s |
沒有邊界檢查 |
sprintfW |
swprintf_s |
沒有邊界檢查 |
lstrncat |
StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx |
有限的錯誤偵測 |
makepath |
||
nsprintf |
sprintf_s |
沒有錯誤偵測或界限檢查 |
strcat |
strcat_s、StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx、strlcat |
有限的錯誤偵測 |
strcatA |
strcat_s、StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx、strlcat |
有限的錯誤偵測 |
strcatW |
strcat_s、StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx、strlcat |
有限的錯誤偵測 |
strcpy |
strcpy_s、StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx、strlcpy |
沒有邊界檢查 |
strcpyA |
strcpy_s、StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx、strlcpy |
沒有邊界檢查 |
strncat |
strncat_s、StringCbCatN、StringCbCatNEx、StringCchCatN、StringCchCatNEx、strlcat |
有限的錯誤偵測 |
strncpy |
strncpy_s、StringCbCopyN、StringCbCopyNEx、StringCchCopyN、StringCchCopyNEx、strlcpy |
有限的錯誤偵測 |
swprintf |
swprintf_s
StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintf、StringCbPrintfEx |
有限的錯誤偵測 |
ualstrcpyW |
strcpy_s、StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx、strlcpy |
沒有邊界檢查 |
vsnprintf |
vsnprintf_s、StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
有限的錯誤偵測 |
vsprintf |
vsprintf_s、StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx、vasprintf |
有限的錯誤偵測 |
vswprintf |
vswprintf_s |
|
wcscat |
wcscat_s、StringCbCat、StringCbCatEx、StringCchCat、StringCchCatEx、wcslcat |
有限的錯誤偵測 |
wcscpy |
wcscpy_s、StringCbCopy、StringCbCopyEx、StringCchCopy、StringCchCopyEx、wcslcpy |
沒有邊界檢查 |
wcsncat |
wcsncat_s、wcslcat |
有限的錯誤偵測 |
wcsncpy |
wcsncpy_s、StringCbCopyN、StringCbCopyNEx、StringCchCopyN、StringCchCopyNEx、wcslcpy |
有限的錯誤偵測 |
wnsprintf |
StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintfEx、StringCchPrintf、StringCchPrintfEx |
無 NULL 字符終止 |
wnsprintfA |
StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintfEx、StringCchPrintf、StringCchPrintfEx |
沒有 NULL 結尾 |
wsprintf |
StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintfEx、StringCchPrintf、StringCchPrintfEx |
沒有 NULL 結尾符號 |
wsprintfA |
StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintfEx、StringCchPrintf、StringCchPrintfEx |
沒有 NULL 終止符 |
wsprintfW |
StringCbPrintf、StringCbPrintf_l、StringCbPrintf_lEx、StringCbPrintfEx、StringCchPrintf、StringCchPrintfEx |
NULL 無終止符 |
wvnsprintf |
StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
無 NULL 結束符 |
wvnsprintfA |
StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
無 NULL 結尾符 |
wvnsprintfW |
StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
無 NULL 結尾或結束符 |
wvsprintf |
StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
沒有 NULL 終止符 |
wvsprintfA |
StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
無空終止符 |
wvsprintfW |
StringCbVPrintf、StringCbVPrintf_l、StringCbVPrintf_lEx、StringCbVPrintfEx、StringCchVPrintf、StringCchVPrintf_l、StringCchVPrintf_lEx、StringCchVPrintfEx |
沒有 NULL 終止符 |