Windows APIが提供するポインタ経由アクセス確認関数IsBadXxxxPtr
系*1 は、Windows Vista以降および Windows Server 2008以降では決して利用してはならない。
安全な例外処理
Windows Vista® および Windows Server® 2008 アプリケーション互換性解説書
以前のバージョンのWindowsでは、IsBadReadPtr
およびIsBadWritePtr
関数を使用してパラメータを検証していました。Windows Vista®およびWindows Server® 2008では、これらの関数は禁止されました。
MSDNより引用(下線部は強調)。他関数にも同様の記載あり。
Important This function is obsolete and should not be used. Despite its name, it does not guarantee that the pointer is valid or that the memory pointed to is safe to use. For more information, see Remarks on this page.
Remarks
(snip)
Threads in a process are expected to cooperate in such a way that one will not free memory that the other needs. Use of this function does not negate the need to do this. If this is not done, the application may fail in an unpredictable manner.Dereferencing potentially invalid pointers can disable stack expansion in other threads. A thread exhausting its stack, when stack expansion has been disabled, results in the immediate termination of the parent process, with no pop-up error window or diagnostic information.
IsBadReadPtr function
注意:2013年6月現在日本語版MSDNでは、"解説(Remarks)" に一部英語版と同じ記載があるものの、「使用禁止」の旨が明記されていない。
関連URL
- IsBadXxxPtr should really be called CrashProgramRandomly | The Old New Thing
- 26.マルチスレッドと IsBadXxxPtr の危険な関係
*1:IsBadCodePtr, IsBadReadPtr, IsBadStringPtr, IsBadWritePtr