Upgrade to Pro — share decks privately, control downloads, hide ads and more …

全銀トラブルとC言語とバッファオーバーフロー

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for tsuda.a tsuda.a
December 27, 2023

 全銀トラブルとC言語とバッファオーバーフロー

全銀トラブル話題にかこつけたC言語でバッファオーバーフローさせる話

Avatar for tsuda.a

tsuda.a

December 27, 2023
Tweet

More Decks by tsuda.a

Other Decks in Technology

Transcript

  1. なぜこんなことが起きるのか? • int は CPU のビット数, long は その倍、という取り決めがあるから? (すみません規格読んでません

    >__<;) • しかし、どうもそういうことでもない模様。 • まとめると以下のような感じ。 #ポリシーがよくわからん データ型 16bit CPU 32bit CPU 64bit CPU int 2 byte (INT_16) 4 byte (INT_32) 4 byte (INT_32) long 4 byte (INT_32) 4 byte (INT_32) 8 byte (INT_64) long long - 8 byte (INT_64) 8 byte (INT_64)
  2. Windows (Visual C++) のデータ型とサイズ • int も long も INT32。

    種類名 バイト 値の範囲 int 4 -2,147,483,648 ~ 2,147,483,647 __int32 4 -2,147,483,648 ~ 2,147,483,647 long 4 -2,147,483,648 ~ 2,147,483,647 https://learn.microsoft.com/ja-jp/cpp/cpp/data-type-ranges?view=msvc-170
  3. では、Window の場合は安心なのか? • そんなこともない。 • 例えば以下のようなコードを考える #include <iostream> struct TEST

    { int *A; int *B; }; int main() { int a = (int)sizeof(TEST); printf("%d¥n", a); } ポインタ変数 (他の言語では参照型といわれるものに近い)