PaddingByteInformationDisclosure (Windows Driver CodeQL クエリ)

概要

メンバーごとに初期化される新しく割り当てられた構造体またはクラスにパディング バイトが含まれている場合、情報が漏洩する可能性があります。

推奨事項

構造体またはクラス内のすべてのパディング バイトが初期化されていることを確認してください。

可能であれば、memset を使用して構造体/クラス全体を初期化します。

次の例は、最初の要素と 2 番目の要素の間のパディングが初期化されていないシナリオを示しています。

typedef enum { Unknown = 0, Known = 1, Other = 2 } MyStructType;
struct MyStruct { MyStructType type; UINT64 id; };
MyStruct testReturn() 
{
	// BAD: Padding between the first and second elements not initialized.
	MyStruct myBadStackStruct = { Unknown };
	return myBadStackStruct;
}

これを修正するには、memset を使用してすべてのバイトを初期化します。

typedef enum { Unknown = 0, Known = 1, Other = 2 } MyStructType;
struct MyStruct { MyStructType type; UINT64 id; };
MyStruct testReturn()
{
	// GOOD: All padding bytes initialized
	MyStruct* myGoodHeapStruct = (struct MyStruct*)malloc(sizeof(struct MyStruct));
	memset(myGoodHeapStruct, 0, sizeof(struct MyStruct));
	return *myGoodHeapStruct;
}

追加の詳細

このクエリは、Microsoft GitHub CodeQL リポジトリにあります。 Windows ドライバー開発者が CodeQL をダウンロードして実行する方法の詳細については、「CodeQL と静的ツールのロゴ テスト」ページを参照してください。