|
| 1 | +<!DOCTYPE html> |
| 2 | +<!-- saved from url=(0043)https://best.openssf.org/labs/template.html --> |
| 3 | +<html lang="ja"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 4 | +<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 5 | +<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | +<link rel="stylesheet" href="https://best.openssf.org/assets/css/style.css"> |
| 7 | +<link rel="stylesheet" href="checker.css"> |
| 8 | +<script src="checker.js"></script> |
| 9 | +<script src="conversion.js"></script> |
| 10 | +<link rel="license" href="https://creativecommons.org/licenses/by/4.0/"> |
| 11 | + |
| 12 | +<!-- See create_labs.md for how to create your own lab! --> |
| 13 | + |
| 14 | +</head> |
| 15 | +<body> |
| 16 | +<!-- For GitHub Pages formatting: --> |
| 17 | +<div class="container-lg px-3 my-5 markdown-body"> |
| 18 | +<h1>ラボ演習 incorrect conversion</h1> |
| 19 | +<p> |
| 20 | +これはセキュアなソフトウェア開発に関するラボ演習です。 |
| 21 | +ラボの詳細については、<a href="ja_introduction.html" target="_blank">概要</a>をご覧ください。 |
| 22 | + |
| 23 | +</p><p> |
| 24 | +</p><h2>ゴール</h2> |
| 25 | +<p> |
| 26 | +<b>予期せぬ型変換が起こらないように、以下のコードを修正しましょう。</b> |
| 27 | + |
| 28 | +</p><p> |
| 29 | +</p><h2>背景</h2> |
| 30 | +<p>この演習では、予期せぬ型変換(または予期せぬ型キャストとも呼ばれる)を特定し修正します。</p> |
| 31 | +<p>以下の例では C プログラムでキューに格納されたメッセージを処理します。メッセージは <tt>get_queue</tt> という関数をコールすることで取得します。<tt>get_queue</tt> 関数にはメッセージを格納できる配列を一つの引数として参照渡しし、関数はこの配列に書き込まれたメッセージの数を戻り値として返します。その後取得したメッセージに対して <tt>process_message</tt> を繰り返し呼び出すことで処理します。</p> |
| 32 | +<p>残念ながら <tt>queue_count</tt> の型と <tt>get_queue</tt> の戻り値の型が一致していないため、メッセージの数を誤って処理してしまう可能性があります。処理回数が少なすぎる場合は情報が失われてしまいます。処理回数が多すぎる場合、 <tt>messages</tt> 配列の未初期化領域のデータを取り扱うことになりエラーを引き起こす恐れがあります。または配列境界を越えた読み込みによってセグメンテーションフォルトを引き起こす可能性があります。</p> |
| 33 | + |
| 34 | +<p></p><h2>タスクの詳細</h2> |
| 35 | +<p></p> |
| 36 | +<p>予期せぬ型変換、または <tt>get_queue</tt> の戻り値が予期せず切り詰められることがないように以下のコードを修正してください。 |
| 37 | +必要に応じて、「ヒント」ボタンと「諦める」ボタンを使用してください。 |
| 38 | +</p> |
| 39 | + |
| 40 | +<p></p> |
| 41 | +<h2>演習 (<span id="grade"></span>)</h2> |
| 42 | +<p></p> |
| 43 | + |
| 44 | +<form id="lab"> |
| 45 | +<pre><code> |
| 46 | +/* get_queue 関数のシグネチャ */ |
| 47 | +unsigned int get_queue(message** messages); |
| 48 | + |
| 49 | +/* メッセージ処理部分... */ |
| 50 | +<input id="attempt0" type="text" size="60" spellcheck="false" value="int queue_count = 0;" style="background-color: yellow;"> |
| 51 | +message* messages = malloc(sizeof(message) * MAX_MESSAGE_COUNT); |
| 52 | +queue_count = get_queue(&messages); |
| 53 | + |
| 54 | +/* 個々のメッセージを順番に処理 */ |
| 55 | +for (unsigned int i = 0; i < queue_count; i++) { |
| 56 | + process_message(messages[i]); |
| 57 | +} |
| 58 | +</code></pre> |
| 59 | +<button type="button" class="hintButton" title="現状へのヒント">ヒント</button> |
| 60 | +<button type="button" class="resetButton" title="初期状態にリセット(現状は失われます)">リセット</button> |
| 61 | +<button type="button" class="giveUpButton" title="諦めて答えを見る">諦める</button> |
| 62 | +<br><br> |
| 63 | +<p> |
| 64 | +<i>このラボは Keith Grant によって開発されました。</i> |
| 65 | +<br><br> |
| 66 | +</p><p id="correctStamp" class="small"> |
| 67 | +<textarea id="debugData" class="displayNone" rows="20" cols="65" readonly=""></textarea> |
| 68 | +</p></form> |
| 69 | +</div><!-- End GitHub pages formatting --> |
| 70 | + |
| 71 | + |
| 72 | +</body></html> |
0 commit comments