ISO/IEC TR 24731-2:2010 情報技術—プログラミング言語、その環境、およびシステムソフトウェアインターフェイス— Cライブラリの拡張—パート2:動的割り当て関数 | ページ 2

※一部、英文及び仏文を自動翻訳した日本語訳を使用しています。

序文

ISO (国際標準化機構) と IEC (国際電気標準会議) は、世界標準化のための専門システムを形成しています。 ISO または IEC のメンバーである国家機関は、技術活動の特定の分野を扱うために、それぞれの組織によって設立された技術委員会を通じて、国際規格の開発に参加しています。 ISO と IEC の技術委員会は、相互に関心のある分野で協力しています。 ISO および IEC と連携して、政府および非政府の他の国際機関もこの作業に参加しています。情報技術の分野では、ISO と IEC が合同技術委員会 ISO/IEC JTC 1 を設立しました。

国際規格は、ISO/IEC 指令で指定された規則に従って起草されます。 2.

合同技術委員会の主な任務は、国際規格を作成することです。合同技術委員会によって採択された国際規格草案は、投票のために各国の機関に回覧されます。国際規格として発行するには、投票を行う国の機関の少なくとも 75% による承認が必要です。

例外的な状況では、技術委員会は、次のいずれかのタイプのテクニカル レポートの発行を提案する場合があります。

  • タイプ 1: 国際規格の発行に必要なサポートが得られない場合、何度も努力したにもかかわらず、
  • タイプ 2, 主題がまだ技術開発中である場合、またはその他の理由により、国際規格に関する合意の可能性はあるが、すぐには実現できない場合。
  • タイプ 3 は、技術委員会が、国際規格として通常公開されているものとは異なる種類のデータを収集した場合 (たとえば、「最新技術」)

タイプ 1 およびタイプ 2 のテクニカル レポートは、発行から 3 年以内に審査され、国際規格に変換できるかどうかが決定されます。タイプ 3 のテクニカル レポートは、それらが提供するデータがもはや有効または有用でないと見なされるまで、必ずしもレビューする必要はありません。

このドキュメントの要素の一部が特許権の対象となる可能性があることに注意してください。 ISO および IEC は、そのような特許権の一部またはすべてを特定する責任を負わないものとします。

タイプ 2 のテクニカル レポートである ISO/IEC TR 24731-2 は、合同技術委員会 ISO/IEC JTC 1, 情報技術、小委員会 SC 22, プログラミング言語、その環境およびシステム ソフトウェア インターフェイスによって作成されました。

ISO/IEC TR 24731 は、以下の部分で構成され、一般的なタイトルは「情報技術 - プログラミング言語、その環境、およびシステム ソフトウェア インターフェイス - С ライブラリの拡張」です

  • Part 1: 境界チェック インターフェイス
  • Part 2: 動的割り当て関数

序章

従来、C ライブラリには、生成される結果を保持するのに十分な大きさの出力文字配列をプログラマが提供することを信頼する多くの関数が含まれていました。これらの関数は、配列が十分な大きさであることをチェックしないだけでなく、そのようなチェックを実行するために必要な情報が不足していることがよくあります。既存のライブラリを使用して安全で堅牢なエラーのないコードを作成することは可能ですが、提供された配列に対して結果が大きすぎる場合、ライブラリは不可解な失敗につながるプログラミング スタイルを促進する傾向があります。

おそらく、最も一般的なプログラミング スタイルは、ほとんどの実際的なケースを処理するのに十分な大きさの文字配列を宣言することです。ただし、プログラムが処理するには大きすぎる文字列を検出した場合、データは配列の末尾を超えて書き込まれ、プログラム内の他の変数が上書きされます。プログラムは、問題が存在するという兆候をまったく得ないため、正常に回復したり失敗したりする機会はありません。

さらに悪いことに、このスタイルのプログラミングは、コンピューターとネットワークのセキュリティを危険にさらしています。デーモンには、慎重に準備されたデータが与えられます。このデータは、バッファをオーバーフローさせ、デーモンを騙して、拒否すべきアクセスを許可させます。

プログラマーがライブラリ関数を呼び出す前に長さを確認する実行時チェックを作成すると、それらの実行時チェックは、ライブラリ関数内で行われる作業を頻繁に複製し、ジョブの実行の副作用として文字列の長さを検出します。

ISO/IEC TR 24731 は、より安全でセキュアなプログラミングを促進する С ライブラリの代替機能を提供します。 ISO/IEC TR 24731-1 は、境界チェックを提供する ISO/IEC 9899:1999 のライブラリ関数の単純な置換関数を提供します。これらの関数は、レガシー コードの元のライブラリ関数の単純な置換として使用できます。 ISO/IEC TR 24731 のこの部分では、動的に割り当てられたメモリを使用してバッファ オーバーフローが発生しないようにするこれらの関数の多くを置き換える方法を示しています。このような関数を使用するには、後でバッファを解放するために追加の呼び出しを追加する必要があるため、これらの関数は古いコードを改造するよりも新しい開発に適しています。

一般に、ISO/IEC TR 24731 のこの部分で説明されている関数は、必要なデータを保持するためにバッファーのサイズが常に自動的に調整されるため、バッファー オーバーフローの問題が発生しないというより大きな保証を提供します。境界チェック関数では、無効なサイズが関数の 1 つに渡された場合、バッファ オーバーフローの問題が発生する可能性がありましたが、そのような問題に対処したように見えました。ただし、動的メモリ割り当てを使用するアプリケーションは、メモリが使い果たされるまでデータが提示されるサービス拒否攻撃を受ける可能性があります。

これらの関数は、広く使用されている既存の実装から引き出されます。これらの関数の多くは ISO/IEC 9945:2003 (POSIX) に含まれており、その国際標準に準拠しています。

ISO/IEC TR 24731 のこの部分のインターフェースの多くは、他の ISO/IEC 国際規格、特に ISO/IEC 9945:200, および ISO/IEC 23360:2006 で指定されたインターフェースから派生しています。

インターフェイスがこれらの国際標準のいずれかから派生したものとして記述されている場合、このリファレンス ページで説明されている機能は、その国際標準に準拠することを意図しています。 ISO/IEC TR 24731 のこの部分で説明されている要件と、参照されている国際規格との間の矛盾は意図的ではありません。 ISO/IEC TR 24731 のこの部分は、基礎となる国際規格に従います。

1. 範囲

ISO/IEC TR 24731 は、ISO/IEC 9899:1999 で指定されたプログラミング言語 C の一連の拡張を指定します。 ISO/IEC 9899:1999 は、ISO/IEC TR 24731 のこの部分の重要なコンテキストと仕様を提供します。箇条 4 は、ISO/IEC 9899:1999 の 6.10.8 に統合されたものとして読む必要があります。箇条 5 は、ISO/IEC 9899:1999 の箇条 7 の指定された副箇条の並列構造に統合されているかのように読む必要があります。

2. 規範的参照

本書の適用には、以下の参考文献が不可欠です。日付のある参考文献については、引用された版のみが適用されます。日付のない参照については、参照文書の最新版 (修正を含む) が適用されます。

  • ISO/IEC 9899:1999, プログラミング言語—C.
  • ISO/IEC 9899:1999/Cor-l:2001, プログラミング言語—С—技術正誤表
  • ISO/IEC 9899:1999/Cor-2:2004, プログラミング言語—С—技術正誤表
  • ISO/IEC 9899:1999/Cor-3:2007, プログラミング言語—С—技術正誤表
  • ISO/IEC 23360:2006, Linux 標準ベース (LSB) コア仕様 3.1

3. 用語、定義、記号

このドキュメントの目的のために、ISO/IEC 9899:1999 に記載されている用語と定義が適用されます。その他の用語は、イタリック体で表示されている箇所で定義されています。

注: ISO/IEC TR 24731 のこの部分で明示的に定義されている用語は、他の場所で定義されている同様の用語を暗示的に参照するものではありません。

Foreword

ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commission) form the specialized system for worldwide standardization. National bodies that are members of ISO or IEC participate in the development of International Standards through technical committees established by the respective organization to deal with particular fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual interest. Other international organizations, governmental and non-governmental, in liaison with ISO and IEC, also take part in the work. In the field of information technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1.

International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, 2.

The main task of the joint technical committee is to prepare International Standards. Draft International Standards adopted by the joint technical committee are circulated to national bodies for voting. Publication as an International Standard requires approval by at least 75% of the national bodies casting a vote.

In exceptional circumstances a technical committee may propose the publication of a Technical Report of one of the following types:

  • type 1, when the required support cannot be obtained for the publication of an International Standard, despite repeated efforts;
  • type 2, when the subject is still under technical development or where for any other reason there is the future but not immediate possibility of an agreement on an International Standard;
  • type 3, when a technical committee has collected data of a different kind from that which is normally published as an International Standard ("state of the art", for example).

Technical Reports of types 1 and 2 are subject to review within three years of publication, to decide whether they can be transformed into International Standards. Technical Reports of type 3 do not necessarily have to be reviewed until the data they provide are considered to be no longer valid or useful.

Attention is drawn to the possibility that some of the elements of this document may be the subject of patent rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights.

ISO/IEC TR 24731-2, which is a Technical Report of type 2, was prepared by Joint Technical Committee ISO/IEC JTC 1, Information technology, Subcommittee SC 22, Programming languages, their environments and system software interfaces.

ISO/IEC TR 24731 consists of the following parts, under the general title Information technology—Programming languages, their environments and system software interfaces—Extensions to the С library:

  • Part 1: Bounds-checking interfaces
  • Part 2: Dynamic Allocation Functions

Introduction

Traditionally, the С library has contained many functions that trust the programmer to provide output character arrays big enough to hold the result being produced. Not only do these functions not check that the arrays are big enough, they frequently lack the information needed to perform such checks. While it is possible to write safe, robust, and error-free code using the existing library, the library tends to promote programming styles that lead to mysterious failures if a result is too big for the provided array.

Perhaps the most common programming style is to declare character arrays large enough to handle most practical cases. However, if the program encounters strings too large for it to process, data is written past the end of arrays overwriting other variables in the program. The program never gets any indication that a problem exists, and so never has a chance to recover or to fail gracefully.

Worse, this style of programming has compromised the security of computers and networks. Daemons are given carefully prepared data that overflows buffers and tricks the daemons into granting access that should be denied.

If the programmer writes run time checks to verify lengths before calling library functions, then those run time checks frequently duplicate work done inside the library functions, which discover string lengths as a side effect of doing their job.

ISO/IEC TR 24731 provides alternative functions for the С library that promote safer, more secure programming. ISO/IEC TR 24731-1 provides simple replacement functions for the library functions of ISO/IEC 9899:1999 that provide bounds checking. Those function can be used as simple replacements for the original library functions in legacy code. This part of ISO/IEC TR 24731 presents replacements for many of these functions that use dynamically allocated memory to ensure that buffer overflow does not occur. Since the use of such functions requires adding additional calls to free the buffers later, these functions are better suited to new developments than to retrofitting old code.

In general, the functions described in this part of ISO/IEC TR 24731 provide much greater assurance that buffer overflow problems will not occur, since buffers are always automatically sized to hold the data required. With the bounds checking functions, if an invalid size was passed to one of the functions, it could still suffer from buffer overflow problems, while appearing to have addressed such issues. Applications that use dynamic memory allocation might, however, suffer from denial of service attacks where data is presented until memory is exhausted.

These functions are drawn from existing implementations that have widespread usage. Many of these functions are included in ISO/IEC 9945:2003 (POSIX) and as such are aligned with that International Standard.

Many of the interfaces in this part of ISO/IEC TR 24731 are derived from interfaces specified in other ISO/IEC International Standards, and in particular ISO/IEC 9945:2003 (including Technical Corrigendum 1), and ISO/IEC 23360:2006.

Where an interface is described as being derived from either of these International Standards, the functionality described on this reference page is intended to be aligned with that International Standard. Any conflict between the requirements described in this part of ISO/IEC TR 24731 and the referenced International Standard is unintentional. This part of ISO/IEC TR 24731 defers to the underlying International Standard.

1. Scope

ISO/IEC TR 24731 specifies a series of extensions of the programming language C, specified by ISO/IEC 9899:1999. ISO/IEC 9899:1999 provides important context and specification for this part of ISO/IEC TR 24731. Clause 4 should be read as if it were merged into ISO/IEC 9899:1999, 6.10.8. Clause 5 should be read as if it were merged into the parallel structure of named subclauses of ISO/IEC 9899:1999, Clause 7.

2. Normative references

The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.

  • ISO/IEC 9899:1999, Programming languages—C.
  • ISO/IEC 9899:1999/Cor-l:2001, Programming languages—С—Technical Corrigendum 1.
  • ISO/IEC 9899:1999/Cor-2:2004, Programming languages—С—Technical Corrigendum 2.
  • ISO/IEC 9899:1999/Cor-3:2007, Programming languages—С—Technical Corrigendum 3.
  • ISO/IEC 23360:2006, Linux standard Base (LSB) core specification 3.1

3. Terms, definitions, and symbols

For the purposes of this document, the terms and definitions given in ISO/IEC 9899:1999 apply. Other terms are defined where they appear in italic type.

NOTE: Terms explicitly defined in this part of ISO/IEC TR 24731 do not refer implicitly to similar terms defined elsewhere.