JP6301851B2 - Program analysis device, error detection device, program analysis method, error detection method, program analysis program, and error detection program - Google Patents

Program analysis device, error detection device, program analysis method, error detection method, program analysis program, and error detection program Download PDF

Info

Publication number
JP6301851B2
JP6301851B2 JP2015028456A JP2015028456A JP6301851B2 JP 6301851 B2 JP6301851 B2 JP 6301851B2 JP 2015028456 A JP2015028456 A JP 2015028456A JP 2015028456 A JP2015028456 A JP 2015028456A JP 6301851 B2 JP6301851 B2 JP 6301851B2
Authority
JP
Japan
Prior art keywords
function
resource
variable
called
source code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
JP2015028456A
Other languages
Japanese (ja)
Other versions
JP2016151855A (en
Inventor
南田 幸紀
幸紀 南田
柴田 弘
弘 柴田
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nippon Telegraph and Telephone Corp
Original Assignee
Nippon Telegraph and Telephone Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nippon Telegraph and Telephone Corp filed Critical Nippon Telegraph and Telephone Corp
Priority to JP2015028456A priority Critical patent/JP6301851B2/en
Publication of JP2016151855A publication Critical patent/JP2016151855A/en
Application granted granted Critical
Publication of JP6301851B2 publication Critical patent/JP6301851B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)

Description

本発明は、ソースコードを静的に解析する技術に関する。   The present invention relates to a technique for statically analyzing source code.

プログラム作成時に誤りを検出する技術が研究されている。そのひとつに、静的コード解析によりプログラムの誤りの可能性のある箇所を検出する技術がある。   Techniques for detecting errors when creating programs are being studied. One of them is a technique for detecting a potential error in a program by static code analysis.

静的コード解析による誤り検出技術の例として、Cプログラムを対象としたmalloc関数で確保したメモリがfree関数で解放されてない箇所を検出する技術、malloc関数で確保した未初期化メモリを参照している箇所を検出する技術などがある(例えば非特許文献1参照)。 As an example of an error detection technique based on static code analysis, refer to a technique for detecting a location in which a memory secured by a malloc function for a C program is not released by a free function, and an uninitialized memory secured by a malloc function. For example, there is a technique for detecting a spot (see Non-Patent Document 1).

W. R. Bush, J. D. Pincus, and D. J. Sielaff, "A static analyzer for finding dynamic programming errors", Software Practice and Experience, 2000年, vol. 30, No. 7, pp. 775-802W. R. Bush, J. D. Pincus, and D. J. Sielaff, "A static analyzer for finding dynamic programming errors", Software Practice and Experience, 2000, vol. 30, No. 7, pp. 775-802

malloc関数やfree関数などの一般的なリソース捕捉関数、リソース解放関数を使用するだけでなく、独自のリソース捕捉関数とリソース解放関数を作成することがある。 In addition to using general resource capture functions and resource release functions such as a malloc function and a free function, unique resource capture functions and resource release functions may be created.

この場合、既存の静的コード解析ツールでは、malloc関数やfree関数などの一般的な関数で捕捉したリソースの未初期化参照は検出できても、ユーザが定義した独自のリソース捕捉関数を用いて捕捉された独自のリソースの未初期化参照を検出することはできないという問題があった。   In this case, the existing static code analysis tool can detect the uninitialized reference of the resource captured by a general function such as the malloc function or the free function, but uses an original resource capture function defined by the user. There was a problem that it was not possible to detect an uninitialized reference of a captured unique resource.

既存の静的コード解析ツールに、ユーザが定義したリソース捕捉関数やリソース解放関数を登録し、malloc関数やfree関数と同等に静的コード解析をする機能を追加することで、ユーザが定義したリソース捕捉関数についても未初期化参照の誤りを検出できると考えられる。 User-defined resources can be added to existing static code analysis tools by registering user-defined resource capture functions and resource release functions and adding static code analysis functions equivalent to malloc and free functions. It is considered that an error in uninitialized reference can be detected for the capture function.

そのためには、ユーザがリソース捕捉・解放関数を管理し、静的コード解析ツールに登録する作業が必要となる。 For this purpose, the user needs to manage the resource capture / release function and register it in the static code analysis tool.

本発明は、上記に鑑みてなされたものであり、ユーザが、ユーザの定義したリソース捕捉・解放関数を管理せずにプログラムのソースコードを解析することによりプログラム中で用いられているリソース捕捉関数やリソース解放関数を抽出し、リソース捕捉関数の使い方の誤りを検出することを目的とする。 The present invention has been made in view of the above, and the resource capturing function used in the program by the user analyzing the source code of the program without managing the resource capturing / release function defined by the user. extracts and resource release function, and an object thereof is to detect errors in the use of the resource capture function.

第1の本発明に係るプログラム解析装置は、リソースを捕捉するリソース捕捉関数と前記リソースを解放するリソース解放関数をソースコードから抽出するプログラム解析装置であって、ソースコードを入力する入力手段と、前記ソースコードに現れる異なる2つの第1関数と第2関数を選択し、ソースコード上で前記第1関数が呼び出された位置から辿ることのできる実行経路の全てにおいて、前記第1関数の返却値を格納する変数の参照状況と前記第2関数の呼出し状況が一般的なリソース格納変数と一般的なリソース解放関数の用いられ方に当てはまる場合は、前記第1関数と前記第2関数のそれぞれをリソース捕捉関数とリソース解放関数として抽出する抽出手段と、を有し、前記一般的なリソース格納変数と一般的なリソース解放関数の用いられ方は、リソース捕捉関数が呼び出された後の実行経路において前記リソース解放関数の呼出し回数は1回以内であって、前記実行経路において前記リソース解放関数が呼び出されないときは、前記実行経路には前記リソース捕捉関数が呼び出された後に分岐があり、当該分岐の後は前記リソース格納変数が参照されていないものであり、前記実行経路において前記リソース解放関数が呼び出されているときは、前記リソース解放関数が呼び出された後の分岐の合流後は前記リソース格納変数が参照されていないことを特徴とする。 A program analysis device according to a first aspect of the present invention is a program analysis device for extracting a resource capture function for capturing a resource and a resource release function for releasing the resource from a source code, and an input means for inputting the source code; Two different first functions and second functions appearing in the source code are selected, and the return value of the first function in all the execution paths that can be traced from the position where the first function is called on the source code. If the reference status of the variable storing the variable and the call status of the second function apply to the general usage of the resource storage variable and the general resource release function, the first function and the second function are comprising extraction means for extracting as a resource acquisition function and the resource release function, wherein the common resource storage variable and common resource release The number is used when the number of calls of the resource release function is within one in the execution path after the resource capture function is called, and when the resource release function is not called in the execution path, The execution path has a branch after the resource capture function is called, and the resource storage variable is not referred to after the branch, and when the resource release function is called in the execution path The resource storage variable is not referenced after merging of branches after the resource release function is called .

第2の本発明に係る誤り検出装置は、第1の本発明に係るプログラム解析装置と、前記プログラム解析装置が抽出したリソース捕捉関数により捕捉されたリソースが未初期化のまま参照されている箇所をソースコード上で検出する検出手段と、を有することを特徴とする。   The error detection apparatus according to the second aspect of the present invention is a program analysis apparatus according to the first aspect of the present invention, and a location where resources captured by a resource capture function extracted by the program analysis apparatus are referred to without being initialized. And detecting means for detecting on the source code.

第3の本発明に係るプログラム解析方法は、リソースを捕捉するリソース捕捉関数と前記リソースを解放するリソース解放関数をソースコードから抽出する、コンピュータにより実行されるプログラム解析方法であって、ソースコードを入力するステップと、前記ソースコードに現れる異なる2つの第1関数と第2関数を選択し、ソースコード上で前記第1関数が呼び出された位置から辿ることのできる実行経路の全てにおいて、前記第1関数の返却値を格納する変数の参照状況と前記第2関数の呼出し状況が一般的なリソース格納変数と一般的なリソース解放関数の用いられ方に当てはまる場合は、前記第1関数と前記第2関数のそれぞれをリソース捕捉関数とリソース解放関数として抽出するステップと、を有し、前記一般的なリソース格納変数と一般的なリソース解放関数の用いられ方は、リソース捕捉関数が呼び出された後の実行経路において前記リソース解放関数の呼出し回数は1回以内であって、前記実行経路において前記リソース解放関数が呼び出されないときは、前記実行経路には前記リソース捕捉関数が呼び出された後に分岐があり、当該分岐の後は前記リソース格納変数が参照されていないものであり、前記実行経路において前記リソース解放関数が呼び出されているときは、前記リソース解放関数が呼び出された後の分岐の合流後は前記リソース格納変数が参照されていないことを特徴とする。 A program analysis method according to a third aspect of the present invention is a program analysis method executed by a computer, wherein a resource capture function for capturing a resource and a resource release function for releasing the resource are extracted from source code. In the input step, the two different first and second functions appearing in the source code are selected, and in all the execution paths that can be traced from the position where the first function is called on the source code, the first function When the reference status of the variable storing the return value of one function and the calling status of the second function apply to the general resource storage variable and the general resource release function, the first function and the first function comprising extracting a respective 2 functions as a resource acquisition function and the resource release function, wherein the common resource The storage variable and a general resource release function are used in such a manner that the number of calls of the resource release function is within one in the execution path after the resource capture function is called, and the resource release function is in the execution path. Is not called, the execution path has a branch after the resource capture function is called, and the resource storage variable is not referenced after the branch, and the resource is released in the execution path. When the function is called, the resource storage variable is not referred to after the branch is merged after the resource release function is called .

第4の本発明に係る誤り検出方法は、コンピュータにより実行される誤り検出方法であって、第3の本発明に係るプログラム解析方法によりリソース捕捉関数を抽出するステップと、前記リソース捕捉関数により捕捉されたリソースが未初期化のまま参照されている箇所をソースコード上で検出するステップと、を有することを特徴とする。   An error detection method according to a fourth aspect of the present invention is an error detection method executed by a computer, the step of extracting a resource capture function by the program analysis method according to the third aspect of the present invention, and the capture by the resource capture function And a step of detecting, on the source code, a location where the resource that has been referenced is referred to without being initialized.

第5の本発明に係るプログラム解析プログラムは、第1の本発明に係るプログラム解析装置の各手段としてコンピュータを動作させることを特徴とする。   A program analysis program according to a fifth aspect of the present invention is characterized by operating a computer as each means of the program analysis apparatus according to the first aspect of the present invention.

第6の本発明に係る誤り検出プログラムは、第2の本発明に係る誤り検出装置の各手段としてコンピュータを動作させることを特徴とする。   An error detection program according to a sixth aspect of the present invention is characterized by operating a computer as each means of the error detection apparatus according to the second aspect of the present invention.

本発明によれば、ユーザが、ユーザの定義したリソース捕捉・解放関数を管理せずにプログラムのソースコードを解析することによりプログラム中で用いられているリソース捕捉関数の使い方の誤りを検出することができる。 According to the present invention, a user detects an error in the usage of a resource capture function used in a program by analyzing the source code of the program without managing the resource capture / release function defined by the user. Can do.

本実施の形態におけるソースコード検査装置の構成を示す機能ブロック図である。It is a functional block diagram which shows the structure of the source code inspection apparatus in this Embodiment. 本実施の形態におけるソースコード検査装置の処理の流れを示すフローチャートである。It is a flowchart which shows the flow of a process of the source code inspection apparatus in this Embodiment. ソースコードの解析処理の流れを示すフローチャートである。It is a flowchart which shows the flow of the analysis process of a source code. ソースコード検査装置が入力するソースコードの例を示す図である。It is a figure which shows the example of the source code which a source code inspection apparatus inputs. 図4のソースコードから作成したサブルーチン展開コードの例を示す図である。It is a figure which shows the example of the subroutine expansion | deployment code produced from the source code of FIG. 図5のサブルーチン展開コードから抽出した関数一覧を示す図である。It is a figure which shows the function list extracted from the subroutine expansion code of FIG. 図5のサブルーチン展開コードから作成した制御フローグラフである。6 is a control flow graph created from the subroutine development code of FIG. 図5のサブルーチン展開コードの解析結果を示す図である。It is a figure which shows the analysis result of the subroutine expansion code of FIG. 図8Aに続く、図5のサブルーチン展開コードの解析結果を示す図である。It is a figure which shows the analysis result of the subroutine expansion | deployment code | cord of FIG. 5 following FIG. 8A. 図8Bに続く、図5のサブルーチン展開コードの解析結果を示す図である。FIG. 8 is a diagram illustrating an analysis result of the subroutine development code of FIG. 5 following FIG. 8B. 本実施の形態で用いるリソース捕捉関数とリソース解放関数とリソース格納変数の出現パタンを説明する図である。It is a figure explaining the appearance pattern of the resource capture function used in this Embodiment, a resource release function, and a resource storage variable. リソース捕捉関数とリソース解放関数の抽出処理の流れを示すフローチャートである。It is a flowchart which shows the flow of the extraction process of a resource capture function and a resource release function. 2つの関数と変数がリソース捕捉関数、リソース解放関数、およびリソース格納変数の出現パタンに当てはまるか否かを調べる処理の流れを示すフローチャートである。It is a flowchart which shows the flow of the process which investigates whether two functions and variables apply to the appearance pattern of a resource capture function, a resource release function, and a resource storage variable.

以下、本発明の実施の形態について図面を用いて説明する。   Hereinafter, embodiments of the present invention will be described with reference to the drawings.

図1は、本実施の形態におけるソースコード検査装置1の構成を示す機能ブロック図である。本ソースコード検査装置1は、ソースコードを入力して解析し、未初期化リソースを参照している誤りを検出する装置である。   FIG. 1 is a functional block diagram showing a configuration of a source code inspection apparatus 1 according to the present embodiment. The source code inspection apparatus 1 is an apparatus that receives and analyzes a source code and detects an error referring to an uninitialized resource.

図1に示すソースコード検査装置1は、入力部11、解析部12、抽出部13、および検出部14を備える。ソースコード検査装置1が備える各部は、演算処理装置、記憶装置等を備えたコンピュータにより構成して、各部の処理がプログラムによって実行されるものとしてもよい。このプログラムはソースコード検査装置1が備える記憶装置に記憶されており、磁気ディスク、光ディスク、半導体メモリ等の記録媒体に記録することも、ネットワークを通して提供することも可能である。以下、各部について説明する。   A source code inspection apparatus 1 shown in FIG. 1 includes an input unit 11, an analysis unit 12, an extraction unit 13, and a detection unit 14. Each unit included in the source code inspection device 1 may be configured by a computer including an arithmetic processing device, a storage device, and the like, and the processing of each unit may be executed by a program. This program is stored in a storage device included in the source code inspection apparatus 1, and can be recorded on a recording medium such as a magnetic disk, an optical disk, or a semiconductor memory, or provided through a network. Hereinafter, each part will be described.

入力部11は、検査対象のソースコードを入力する。後述の実施例では、C言語のソースコードを入力する例で説明するが、C言語のみに限らず、他のプログラミング言語にも適用できる。   The input unit 11 inputs a source code to be inspected. In the embodiment described later, an example in which C language source code is input will be described. However, the present invention is not limited to C language but can be applied to other programming languages.

解析部12は、入力部11が入力したソースコードを解析する。具体的には、解析部12は、ソースコード中でサブルーチン呼出し(関数呼出し)している箇所に、そのサブルーチン(関数)の定義コードを書き足してサブルーチン展開コードを作成し、サブルーチン展開コードの各行について、関数呼出しをしているか、関数の返却値を格納する変数はなにか、関数の引数はなにか、分岐しているか、分岐後の合流地点はどこか、利用されている変数はなにか、などの情報を解析する。また、解析部12は、サブルーチン展開コードの各行をノードとした制御フローグラフを作成する。   The analysis unit 12 analyzes the source code input by the input unit 11. Specifically, the analysis unit 12 creates a subroutine expansion code by adding the definition code of the subroutine (function) to the place where the subroutine call (function call) is made in the source code, and generates each line of the subroutine expansion code. Is a function call, what is the variable that stores the return value of the function, what is the argument of the function, whether it is branched, where is the merge point after the branch, what variable is being used, etc. Analyze information. The analysis unit 12 also creates a control flow graph with each line of the subroutine expansion code as a node.

抽出部13は、解析部12の解析結果を元に、リソース捕捉関数とリソース解放関数のペアを抽出する。具体的には、ソースコード中の2つの異なる関数について、リソース捕捉関数とリソース解放関数が使われるパタンに合致するか否かを調べ、ソースコードの中からリソース捕捉関数とリソース解放関数のペアを抽出する。例えば、リソース捕捉関数とリソース解放関数が使われるパタンとしては、リソース捕捉関数が呼出されて、その結果がリソース格納変数に代入され、リソース格納変数を介してリソースが使われた後で、リソース解放関数が呼出されるパタンがある。この場合、リソース捕捉関数が呼出された後にリソース格納変数が参照される。リソース解放関数より後にリソース格納変数が参照されることもない。また、リソース捕捉関数が呼出された後にリソース解放関数が呼出されるが、リソース解放関数が2回以上呼出されることはない。後述する実施例では、リソース捕捉関数及びリソース解放関数のエラー処理を考慮したパタンを用いてリソース捕捉関数とリソース解放関数のペアを抽出する。 The extraction unit 13 extracts a resource capture function and resource release function pair based on the analysis result of the analysis unit 12. Specifically, for two different functions in the source code, check whether the resource capture function and the resource release function match the pattern used, and set the resource capture function and resource release function pair in the source code. Extract. For example, as the pattern resource acquisition function and the resource release function is used, it is called the resource acquisition function, the result is assigned to the resource storage variable, after the used resources via the resource storage variable, resource release There is a pattern where the function is called. In this case, the resource storage variable is referenced after the resource capture function is called. The resource storage variable is not referenced after the resource release function. Further, the resource release function is called after the resource capture function is called, but the resource release function is never called more than once. In Examples described later, it extracts a pair of resource acquisition function and the resource release function using the pattern in consideration of the error handling of resource acquisition function and resource release function.

検出部14は、抽出部13が抽出したリソース捕捉関数が返す未初期化リソースを参照している箇所を検出する。既存の静的コード解析ツールでは、mallocやnewなどの一般的なリソース捕捉関数で捕捉したリソースの未初期化参照を解析できる。既存の静的コード解析ツールに、抽出部13が抽出したリソース捕捉関数及びリソース解放関数のペアを登録することで検出部14を実現する。未初期化リソースの参照を検出する方法としては、例えば非特許文献1に記載されている未初期化メモリの参照を検出する方法を用いることができる。 The detection unit 14 detects a location that refers to an uninitialized resource returned by the resource capturing function extracted by the extraction unit 13. Existing static code analysis tools can analyze uninitialized references of resources captured with common resource capture functions such as malloc and new. The detection unit 14 is realized by registering a resource capture function and resource release function pair extracted by the extraction unit 13 in an existing static code analysis tool. As a method for detecting a reference to an uninitialized resource, for example, a method for detecting a reference to an uninitialized memory described in Non-Patent Document 1 can be used.

次に、本実施の形態におけるソースコード検査装置1の動作について説明する。   Next, the operation of the source code inspection apparatus 1 in this embodiment will be described.

図2は、本実施の形態におけるソースコード検査装置1の処理の流れを示すフローチャートである。   FIG. 2 is a flowchart showing a processing flow of the source code inspection apparatus 1 in the present embodiment.

入力部11が検査対象のソースコードを入力する(ステップS1)。   The input unit 11 inputs the source code to be inspected (step S1).

解析部12がソースコードを解析する(ステップS2)。ソースコードの解析処理の詳細については後述する。   The analysis unit 12 analyzes the source code (step S2). Details of the source code analysis processing will be described later.

抽出部13が、ソースコードの解析結果を元に、リソース捕捉関数とリソース解放関数のペアをソースコードから抽出する(ステップS3)。リソース捕捉関数とリソース解放関数の抽出処理の詳細については後述する。 The extraction unit 13 extracts a resource capture function and resource release function pair from the source code based on the analysis result of the source code (step S3). Details of the resource capture function and resource release function extraction processing will be described later.

そして、検出部14が、一般的なリソース捕捉関数に加えて、抽出部13の抽出したリソース捕捉関数が捕捉したリソースも含めて、未初期化リソースを参照している箇所を検出する(ステップS4)。   Then, the detection unit 14 detects a location that refers to an uninitialized resource including a resource captured by the resource capture function extracted by the extraction unit 13 in addition to a general resource capture function (step S4). ).

(ソースコードの解析処理)
次に、ソースコードの解析処理について説明する。
(Source code analysis processing)
Next, source code analysis processing will be described.

図3は、ソースコードの解析処理の流れを示すフローチャートである。以下では、図4に示すソースコードを入力した具体例とともにソースコードの解析処理を説明する。   FIG. 3 is a flowchart showing the flow of source code analysis processing. Below, the analysis process of a source code is demonstrated with the specific example which input the source code shown in FIG.

解析部12は、入力部11が入力したソースコードからサブルーチン展開コードを作成する(ステップS21)。図5に、図4のソースコードから作成したサブルーチン展開コードの例を示す。図5の例では、解析部12は、main関数から呼び出されているfinish関数とabort_program関数のソースコードを呼び出した箇所の下に展開して追記している。解析部12は、さらにfinish関数から呼び出されているabort_program関数も展開して追記している。具体的には、符号101A,101B,101Cで示す箇所にabort_program関数を展開し、符号102で示す箇所にfinish関数を展開した。符号101B,101Cで示す箇所に展開したabort_program関数はfinish関数から呼び出されたものである。   The analysis unit 12 creates a subroutine development code from the source code input by the input unit 11 (step S21). FIG. 5 shows an example of a subroutine expansion code created from the source code of FIG. In the example of FIG. 5, the analysis unit 12 expands and appends the source code of the finish function and abort_program function called from the main function under the location where the source code is called. The analysis unit 12 further expands and adds an abort_program function called from the finish function. Specifically, the abort_program function is expanded at the locations indicated by reference numerals 101A, 101B, and 101C, and the finish function is expanded at the location indicated by reference numeral 102. The abort_program function expanded at the locations indicated by reference numerals 101B and 101C is called from the finish function.

サブルーチン展開コードでは、関数を展開した箇所の行番号として、呼び出し元の行番号に元々のソースコードの行番号を付与した行番号(以下、「コールスタック付き行番号」と称する)を付与する。例えば、符号101Aで示した箇所のabort_program関数は、main関数の9行目で呼び出されており、abort_program関数は、図4のソースコードの28−30行目に記述されているので、9行目に展開したabort_program関数の各行に行番号9−28,9−29,9−30を付与する。別の例では、符号102で示した箇所のfinish関数はmain関数の13行目で呼び出されており、符号101Bで示した箇所のabort_program関数はfinish関数の23行目で呼び出されているので、符号101Bで示した箇所のabort_program関数の各行に行番号13−23−28,13−23−29,13−23−30を付与する。   In the subroutine development code, the line number obtained by adding the line number of the original source code to the caller line number (hereinafter referred to as “line number with call stack”) is assigned as the line number of the location where the function is expanded. For example, the abort_program function at the position denoted by reference numeral 101A is called on the ninth line of the main function, and the abort_program function is described on the 28th to 30th lines of the source code in FIG. Line numbers 9-28, 9-29, and 9-30 are assigned to the lines of the abort_program function expanded in FIG. In another example, the finish function at the location indicated by reference numeral 102 is called at the 13th line of the main function, and the abort_program function at the location indicated by reference numeral 101B is called at the 23rd line of the finish function. Row numbers 13-23-28, 13-23-29, and 13-23-30 are assigned to each row of the abort_program function at the location indicated by reference numeral 101B.

続いて、解析部12は、サブルーチン展開コードから関数を抽出して関数一覧を作成する(ステップS22)。図6に、図5のサブルーチン展開コードから抽出した関数一覧を示す。解析部12は、抽出した関数に関数IDを付与する。   Subsequently, the analysis unit 12 extracts a function from the subroutine development code and creates a function list (step S22). FIG. 6 shows a list of functions extracted from the subroutine expansion code of FIG. The analysis unit 12 assigns a function ID to the extracted function.

続いて、解析部12は、サブルーチン展開コードから制御フローグラフを作成する(ステップS23)。制御フローグラフは、プログラムを実行したときの制御の流れを有向グラフで表したものである。図7に、図5のサブルーチン展開コードから作成した制御フローグラフを示す。本実施の形態では、コールスタック付き行番号をノードとし、呼び出された関数の内部に制御の流れを追うステップイン接続と、関数の内部に制御の流れを追わないステップオーバー接続の2つのエッジを付与した。図7の点線で示すエッジがステップイン接続を示し、実線で示すエッジがステップオーバー接続を示す。なお、本実施の形態では、プログラムの制御構造のひとつであるループは考慮せずに、ループは、1回だけ実行されるものとみなして解析する。   Subsequently, the analysis unit 12 creates a control flow graph from the subroutine development code (step S23). The control flow graph is a directed graph representing the flow of control when a program is executed. FIG. 7 shows a control flow graph created from the subroutine development code of FIG. In this embodiment, the line number with a call stack is a node, and two edges of a step-in connection that follows the flow of control inside the called function and a step-over connection that does not follow the flow of control inside the function are provided. Granted. An edge indicated by a dotted line in FIG. 7 indicates a step-in connection, and an edge indicated by a solid line indicates a step-over connection. In the present embodiment, a loop that is one of the control structures of a program is not considered, and the loop is analyzed by assuming that it is executed only once.

そして、解析部12は、サブルーチン展開コードを解析する(ステップS24)。図8A〜8Cは、解析部12によるサブルーチン展開コードの解析結果を示す図である。本実施の形態では、サブルーチン展開コードの行ごとに、エイリアス集合、関数呼出し、関数ID、関数返却値格納変数、引数、分岐、合流行番号、および効果有り参照されている変数を抽出する。   Then, the analysis unit 12 analyzes the subroutine development code (step S24). 8A to 8C are diagrams illustrating the analysis results of the subroutine development code by the analysis unit 12. In the present embodiment, an alias set, a function call, a function ID, a function return value storage variable, an argument, a branch, a popular number, and a variable with reference to an effect are extracted for each line of the subroutine expansion code.

エイリアス集合は、ソースコードに現れる変数のエイリアス組の集合である。本実施の形態では、該当行を実行後の時点でのエイリアス集合を求めている。例えば、4行目のcmdと5行目のcmdは同じものであるので、行番号と変数名をペアにしたフロー依存変数(4,cmd),(5,cmd)をエイリアス集合に加えている。エイリアス集合の要素は、変数名が異なるときも同じものとみなすことができる。属するエイリアス集合が異なるときは異なる変数とみなすことができる。本実施の形態で想定するエイリアス解析はフローセンシティブエイリアス解析であり、ソースコードの行によって変数の関係性が変わることを考慮するものである。なお、フロー依存変数とは、変数名rと変数が出現したコールスタック付き行番号kの組(k, r)である。   An alias set is a set of alias sets of variables that appear in the source code. In this embodiment, an alias set at the time after execution of the corresponding row is obtained. For example, since the cmd on the 4th line and the cmd on the 5th line are the same, the flow dependent variables (4, cmd), (5, cmd) in which the line number and the variable name are paired are added to the alias set. . The elements of the alias set can be considered the same when the variable names are different. When different alias sets belong, they can be regarded as different variables. The alias analysis assumed in this embodiment is a flow-sensitive alias analysis, and considers that the relationship of variables changes depending on the line of the source code. The flow dependent variable is a set (k, r) of the variable name r and the line number k with the call stack in which the variable appears.

関数呼出しは、当該行で関数を呼び出しているか否かを示す。関数を呼び出しているときは、呼び出している関数のID、呼び出している関数の返却値を格納する変数、および関数の引数を記載する。ソースコード上で関数に渡されている引数がアドレス演算子(&)や間接演算子(*)で修飾されている変数の場合は、これらの演算子を外した変数も解析結果の引数に記載する。なぜならば、アドレス演算子や間接演算子で修飾された変数が参照される前に、アドレス演算子や間接演算子で修飾されていない変数の値が参照されるからである。例えば、ソースコード上で関数に渡されている引数が&aの場合は、解析結果の引数の項目には、&aとaを記載する。別の例では、ソースコード上で関数に渡されている引数が**aの場合は、解析結果の引数の項目には、**aと*aとaを記載する。   The function call indicates whether or not a function is called on the line. When a function is called, the ID of the calling function, a variable for storing the return value of the calling function, and the function argument are described. If the argument passed to the function in the source code is a variable that is qualified with the address operator (&) or indirect operator (*), the variable that excludes these operators is also included in the argument of the analysis result To do. This is because the value of the variable not modified by the address operator or indirect operator is referred to before the variable modified by the address operator or indirect operator is referenced. For example, when the argument passed to the function in the source code is & a, & a and a are described in the argument item of the analysis result. In another example, when the argument passed to the function on the source code is ** a, ** a, * a, and a are described in the argument item of the analysis result.

分岐は、当該行が分岐であるか否かを示す。分岐があるときは分岐したルートの合流先を合流行番号に記載する。if文の分岐では、then節とelse節に実行経路が分岐するが、then節とelse節の後の行が合流先となる。   A branch indicates whether or not the row is a branch. If there is a branch, enter the destination of the branched route in the popular number. In the branching of the “if” statement, the execution path branches to the “then” clause and the “else” clause, but the line after the “then” clause and the “else” clause becomes the merge destination.

効果有り参照されている変数は、当該行で実質的に使われている変数を記載する。より具体的には、変数vが効果有り参照されるとは、次に示すいずれかの条件を満たす場合であると定義する。   The variable that is referred to as effective refers to the variable that is actually used in the line. More specifically, it is defined that the variable v is referred to as being effective if it satisfies any of the following conditions.

(1)変数vの値が読み取られ、かつ、別の変数wに値が代入され、その結果、変数vと変数wがエイリアスの関係にならない
(2)変数vが関数の引数として参照される
(3)変数vが条件判定文の条件式の中で参照される
(1) The value of the variable v is read and the value is assigned to another variable w. As a result, the variable v and the variable w do not have an alias relationship. (2) The variable v is referred to as a function argument. (3) The variable v is referenced in the conditional expression of the condition judgment statement

以下、効果有り参照されている変数の具体例を説明する。例えば、a=vと記載された行を考えると、この行を実行した結果、変数aは変数vのエイリアスになるので、この行では変数vは効果有り参照されていない。別の例で、a=v+1が記載された行を考えると、変数vの値が読み取られ、かつ、変数aに値がセットされ、その結果、変数aと変数vはエイリアスの関係にならないので、この行では変数vは効果有り参照されている。さらに、この行の変数aについて考えると、変数aの値は参照されていないので、変数aは効果有り参照されていない。   Hereinafter, specific examples of variables that are referred to as effective will be described. For example, when a line with a = v is considered, as a result of executing this line, the variable a becomes an alias of the variable v. Therefore, the variable v is not referred to in this line because of the effect. In another example, if a line with a = v + 1 is considered, the value of the variable v is read and the value is set in the variable a. As a result, the variable a and the variable v are not in an alias relationship. In this line, the variable v is referred to as effective. Further, considering the variable a in this row, the value of the variable a is not referenced, and therefore the variable a is not referred to as effective.

また別の例で、*v=a+1が記載された行を考えると、変数vの値が参照され、デリファレンスされて変数*vに値が格納されていて、その結果、変数vと変数*vはエイリアスの関係にならないので、変数vは効果有り参照されている。さらに別の例で、a=&vが記載された行を考えると、変数vのアドレスは参照されているが変数vの値は参照されていないので、変数vは効果有り参照されていない。   In another example, considering a line in which * v = a + 1 is described, the value of the variable v is referred to, dereferenced and stored in the variable * v, and as a result, the variable v and the variable * Since v does not have an alias relationship, the variable v is referred to as effective. In yet another example, when a line in which a = & v is described is considered, the address of the variable v is referred to, but the value of the variable v is not referred to. Therefore, the variable v is not referred to effectively.

条件式の中で参照される例を挙げると、例えばif(v){・・・}が記載された行では、条件判定文の条件式の中で変数vの値が参照されているので、変数vは効果有り参照されている。   If the example referred in a conditional expression is given, for example, in the line where if (v) {...} Is described, the value of the variable v is referenced in the conditional expression of the conditional judgment statement. The variable v is referred to as effective.

(リソース捕捉関数とリソース解放関数の抽出処理)
次に、リソース捕捉関数とリソース解放関数の抽出処理について説明する。
(Resource capture function and resource release function extraction process)
Next, the resource capture function and resource release function extraction processing will be described.

ソースコード中の一般的なリソース捕捉関数と一般的なリソース解放関数の出現パタンとしては、例えば最もシンプルなパタンとして、リソース捕捉関数の返却値を格納する変数(リソース格納変数)が指定されてリソース捕捉関数が呼び出された後、リソース格納変数が指示するリソースが使用され、その後リソース解放関数が1回だけ呼び出されるパタンがある。リソース格納変数は、リソース捕捉関数の前とリソース解放関数の後に使用されることはない。このような出現パタンに当てはまる2つの関数はリソース捕捉関数とリソース解放関数の可能性があると推定できる。 As the appearance pattern of the general resource capture function and general resource release function in the source code, for example, the variable (resource storage variable) that stores the return value of the resource capture function is specified as the simplest pattern. After the capture function is called, there is a pattern in which the resource indicated by the resource storage variable is used, and then the resource release function is called only once. Resource storage variables are never used before the resource capture function and after the resource release function. It can be estimated that two functions that fall under such an appearance pattern may be a resource capture function and a resource release function.

本実施の形態では、リソース捕捉関数のエラー処理とリソース解放関数のエラー処理も含めたパタンに当てはまる2つの関数をリソース捕捉関数とリソース解放関数として抽出する。 In the present embodiment, two functions corresponding to the pattern including the error processing of the resource capturing function and the error processing of the resource releasing function are extracted as the resource capturing function and the resource releasing function.

図9は、本実施の形態で用いるリソース捕捉関数とリソース解放関数とリソース格納変数の出現パタンを説明する図である。図9に示すパタンは、リソース捕捉関数の後にエラー処理があり、リソース解放関数の後にエラー処理があるパタンである。リソース捕捉関数の後のエラー処理内では、リソース格納変数が参照されることはなく、リソース解放関数が呼び出されずに処理を抜ける。また、リソース解放関数の後のエラー処理内では、ログ出力などでリソース格納変数が参照されることがあるが、エラー処理を抜けた後にリソース格納変数が参照されることはない。 FIG. 9 is a diagram for explaining the appearance pattern of the resource capture function, the resource release function, and the resource storage variable used in the present embodiment. The pattern shown in FIG. 9 is a pattern in which error processing is performed after the resource capture function and error processing is performed after the resource release function. In the error processing after the resource capture function, the resource storage variable is not referred to, and the processing is terminated without calling the resource release function. Further, in the error processing after the resource release function, the resource storage variable may be referred to for log output or the like, but the resource storage variable is not referred to after exiting the error processing.

抽出部13は、解析部12の解析結果を元に、関数一覧の全ての2つの関数の組み合わせについて、リソース格納変数を推定し、2つの関数とリソース格納変数の出現パタンが図9に示した、リソース捕捉関数とリソース解放関数とリソース格納変数の出現パタンに当てはまるか否かを調べて、パタンに当てはまる場合は、2つの関数がリソース捕捉関数とリソース解放関数であるとして抽出する。以下、リソース捕捉関数とリソース解放関数の抽出処理の流れについて説明する。 Based on the analysis result of the analysis unit 12, the extraction unit 13 estimates resource storage variables for all combinations of two functions in the function list, and the appearance patterns of the two functions and the resource storage variables are shown in FIG. Whether the resource capturing function, the resource releasing function, and the appearance pattern of the resource storage variable apply is checked. If the pattern is applied, the two functions are extracted as the resource capturing function and the resource releasing function. Hereinafter, the flow of extraction processing of the resource capture function and the resource release function will be described.

図10,11は、リソース捕捉関数とリソース解放関数の抽出処理の流れを示すフローチャートである。 10 and 11 are flowcharts showing the flow of the process of extracting the resource capturing function and the resource releasing function.

まず、抽出部13は、リソース捕捉関数とリソース解放関数のペアを格納する関数ペア集合を空集合にする(ステップS31)。 First, the extraction unit 13 sets an empty set to a function pair set that stores a pair of a resource capture function and a resource release function (step S31).

抽出部13は、関数一覧から2つの関数f,gを選択し、全ての関数の組み合わせについて以下の処理を繰り返す(ステップS32)。関数一覧に含まれる関数IDの集合をFとするとf∈F,g∈F,f≠gである。以下の処理では、関数fがリソース捕捉関数であるか、関数gがリソース解放関数であるかを調べる。 The extraction unit 13 selects two functions f and g from the function list, and repeats the following processing for all function combinations (step S32). If a set of function IDs included in the function list is F, fεF, gεF, and f ≠ g. In the following processing, it is checked whether the function f is a resource capture function or the function g is a resource release function.

抽出部13は、解析結果を参照し、関数fが呼び出されている行番号kを挙げて行番号集合Kを作成する(ステップS33)。   The extraction unit 13 refers to the analysis result and creates a line number set K by listing the line number k at which the function f is called (step S33).

抽出部13は、解析結果を参照し、行番号k∈Kと行番号kにおいて関数fの返却値を格納している変数rのペアをフロー依存変数(k,r)としてフロー依存変数集合Rを作成する(ステップS34)。この処理により、関数fが呼び出されている行番号kとリソース格納変数の候補である変数rをペアとしたフロー依存変数集合R={(k1,r1),(k2,r2),・・・}が作成される。   The extraction unit 13 refers to the analysis result, and sets a flow-dependent variable set R as a flow-dependent variable (k, r) with a pair of variables r storing the return value of the function f at the line number kεK and the line number k. Is created (step S34). By this processing, the flow dependent variable set R = {(k1, r1), (k2, r2),..., Which is a pair of the line number k where the function f is called and the variable r which is a candidate for the resource storage variable. } Is created.

抽出部13は、好適パタン数を0に設定し、全てのフロー依存変数(k,r)∈Rについて、行番号k以降の実行経路において、2つの関数f,gと変数rの出現パタンが図9に示したパタンに当てはまるか否か判定する(ステップS35−S37)。ステップS36の判定結果がポジティブであるときは好適パタン数に1加算する。2つの関数f,gと変数rの出現パタンが図9に示したパタンに当てはまるか否か判定する処理の詳細は後述する。   The extraction unit 13 sets the number of suitable patterns to 0, and for all flow-dependent variables (k, r) εR, the appearance patterns of the two functions f and g and the variable r are present in the execution path after the line number k. It is determined whether or not the pattern shown in FIG. 9 is applicable (steps S35 to S37). When the determination result in step S36 is positive, 1 is added to the number of suitable patterns. Details of the process for determining whether the appearance patterns of the two functions f and g and the variable r apply to the pattern shown in FIG. 9 will be described later.

そして、全てのフロー依存変数(k,r)∈Rの判定結果がポジティブであるときは、関数f,gはリソース捕捉関数とリソース解放関数であるとして、関数ペア(f,g)を関数ペア集合に追加する(ステップS38)。フロー依存変数の数|R|と好適パタン数が一致するときは全てのフロー依存変数の判定結果がポジティブであるので、関数ペア(f,g)を関数ペア集合に追加する。ただし、行番号kの数|K|とフロー依存変数の数|R|が一致しない場合は、ソースコード中に関数fの返却値が変数に格納されない箇所があり、関数fはリソース捕捉関数ではないので、関数ペア(f,g)を関数ペア集合に追加しない。 When the determination results of all the flow dependent variables (k, r) εR are positive, the function pair (f, g) is assumed to be a function pair, assuming that the functions f, g are a resource capture function and a resource release function. It adds to a set (step S38). When the number of flow dependent variables | R | matches the number of suitable patterns, the determination result of all the flow dependent variables is positive, so the function pair (f, g) is added to the function pair set. However, if the number of line numbers k | K | and the number of flow-dependent variables | R | do not match, there are places in the source code where the return value of the function f is not stored in the variable. Therefore, the function pair (f, g) is not added to the function pair set.

抽出部13は、全ての関数ペア(f,g),f∈F,g∈F,f≠gについて、ステップS33〜S38の処理を行う(ステップS39)。   The extraction unit 13 performs steps S33 to S38 for all function pairs (f, g), fεF, gεF, and f ≠ g (step S39).

以上の処理により、リソース捕捉関数とリソース解放関数のペアである可能性の関数ペアが関数ペア集合に格納される。 Through the above processing, a function pair that is likely to be a pair of a resource capture function and a resource release function is stored in the function pair set.

続いて、2つの関数f,gと変数rの出現パタンが図9に示したパタンに当てはまるか否か判定する処理の詳細について説明する。   Next, details of a process for determining whether or not the appearance patterns of the two functions f and g and the variable r apply to the pattern shown in FIG. 9 will be described.

図11は、2つの関数f,gと変数rがリソース捕捉関数、リソース解放関数、およびリソース格納変数の出現パタンに当てはまるか否かを調べる処理の流れを示すフローチャートである。図11に示す処理では、関数fが呼び出された行番号kより後の実行経路の全てにおいて、関数f,gと変数rの出現パタンが図9に示したパタンに当てはまるか否かを判定する。 FIG. 11 is a flowchart showing a flow of processing for checking whether or not two functions f and g and a variable r are applicable to the resource capture function, the resource release function, and the appearance pattern of the resource storage variable. In the processing shown in FIG. 11, it is determined whether or not the appearance patterns of the functions f and g and the variable r are applicable to the pattern shown in FIG. 9 in all the execution paths after the line number k where the function f is called. .

抽出部13は、制御フローグラフを参照し、関数fが呼び出された行番号kより後の実行経路pを全て挙げて実行経路集合Pを作成する(ステップS51)。ここで、実行経路pを作成する際には、関数f,gへのステップイン接続はたどらない。関数f,g以外の関数へのステップイン接続がある場合はステップイン接続だけをたどる。1ノードを起点とするステップオーバー接続が複数ある場合には、接続の選び方に応じた実行経路をそれぞれ作成する。実行経路pは、コールスタック付き行番号の順序付き集合p={n,n,・・・,n}で表す。 The extraction unit 13 refers to the control flow graph and creates an execution path set P by listing all execution paths p after the line number k from which the function f is called (step S51). Here, when the execution path p is created, the step-in connection to the functions f and g is not followed. If there is a step-in connection to a function other than the functions f and g, only the step-in connection is followed. When there are a plurality of step-over connections starting from one node, an execution path corresponding to how to select the connection is created. The execution path p is represented by an ordered set p = {n 1 , n 2 ,..., N m } of line numbers with call stacks.

抽出部13は、好適経路数、捕捉失敗候補経路数を0に設定し、全ての実行経路p∈Pについて、以下の処理を繰り返す(ステップS52)。好適経路数は実行経路集合Pのなかで図9のパタンに当てはまった実行経路pの数を示す。捕捉失敗候補経路数はリソース捕捉関数のエラー処理に当てはまった実行経路pの数を示す。   The extraction unit 13 sets the number of preferred routes and the number of acquisition failure candidate routes to 0, and repeats the following processing for all execution routes pεP (step S52). The preferred number of paths indicates the number of execution paths p that match the pattern in FIG. The number of acquisition failure candidate paths indicates the number of execution paths p applicable to the error processing of the resource acquisition function.

抽出部13は、補足後使用区間調査フラグをtrueに設定する(ステップS53)。補足後使用区間調査フラグは、実行経路pの検査結果を示すフラグであり、実行経路pが図9のパタンに当てはまらないときはfalseが設定される。   The extraction unit 13 sets the post-supplemented used section survey flag to true (step S53). The post-supplemented used section survey flag is a flag indicating the inspection result of the execution path p, and false is set when the execution path p does not correspond to the pattern of FIG.

抽出部13は、実行経路p上で関数gが2回以上呼び出されているか判定する(ステップS54)。リソース解放関数が2回以上呼び出されることはないので、関数gが2回以上呼び出されている場合は(ステップS54のYES)、補足後使用区間調査フラグをfalseに設定する(ステップS60)。 The extraction unit 13 determines whether the function g has been called twice or more on the execution path p (step S54). Since the resource release function is not called twice or more, if the function g is called twice or more (YES in step S54), the post-supplemented used section survey flag is set to false (step S60).

抽出部13は、実行経路p上で関数gが1回呼び出されているか判定する(ステップS55)。関数gが呼び出されていない場合は(ステップS55のNO)、実行経路pはリソース捕捉関数のエラー処理の経路である可能性があるのでステップS58に進む。   The extraction unit 13 determines whether the function g is called once on the execution path p (step S55). If the function g has not been called (NO in step S55), the execution path p may be an error processing path for the resource capture function, and the process proceeds to step S58.

実行経路p上で関数gが1回呼び出されている場合(ステップS55のYES)、抽出部13は、関数gが呼び出されるまでに変数rが使用されているか判定する(ステップS56)。変数rが使用されていない場合は(ステップS56のNO)、補足後使用区間調査フラグをfalseに設定する(ステップS60)。   When the function g is called once on the execution path p (YES in step S55), the extraction unit 13 determines whether the variable r is used before the function g is called (step S56). If the variable r is not used (NO in step S56), the post-supplemented used section survey flag is set to false (step S60).

なお、「変数rが使用される」とは、具体的には、「フロー依存変数(k,r)のエイリアスのいずれかが効果有り参照される」という意味である。記述を簡潔にするために、本実施例では「変数rが使用される」と記述することにする。   Note that “the variable r is used” specifically means “one of the aliases of the flow-dependent variable (k, r) is referred to as effective”. In order to simplify the description, it is described in this embodiment that “variable r is used”.

ここで、ステップS56の変数rの使用判定について説明する。関数gは実行経路pのj番目の要素nに対応する行で呼び出されているとする。抽出部13は、実行経路pの先頭の要素nからj−1番目の要素nj−1までのいずれかの要素において、解析結果の効果有り参照されている変数の項目に変数rのエイリアスのいずれかが記載されているか否かを調べる。変数rのエイリアスが効果有り参照されている場合はステップS56の判定結果はYESとなり、変数rのエイリアスが効果有り参照されていない場合はステップS56の判定結果はNOとなる。 Here, the use determination of the variable r in step S56 will be described. It is assumed that the function g is called in the line corresponding to the jth element nj in the execution path p. Extraction unit 13, in any of the elements from the first element n 1 to j-1 th element n j-1 execution path p, the item of variable referenced there effects of the analysis result of the variable r aliases It is checked whether any of the above is described. If the alias of the variable r is referred to as effective, the determination result in step S56 is YES. If the alias of the variable r is not referred to as effective, the determination result in step S56 is NO.

関数gが呼び出されるまでに変数rが使用されている場合(ステップS56のYES)、抽出部13は、関数gが呼び出された後、変数rが使用されているか判定する(ステップS57)。変数rが使用されている場合は(ステップS57のYES)、補足後使用区間調査フラグをfalseに設定する(ステップS60)。   When the variable r is used before the function g is called (YES in step S56), the extraction unit 13 determines whether the variable r is used after the function g is called (step S57). When the variable r is used (YES in step S57), the post-supplemented use section survey flag is set to false (step S60).

ただし、リソース解放関数のエラー処理の経路では、関数gが呼び出された後も変数rが使用される可能性があるので、リソース解放関数のエラー処理と思われる箇所は飛ばして判定する。具体的には、抽出部13は、実行経路pの中で、要素nの後に、要素nと同階層で最初に出現する分岐を探し、分岐が存在する場合は実行経路pの中でその分岐の合流先である要素n以降の要素をステップS57の判定対象とする。また、分岐が存在しない場合や分岐の途中でプログラムが終了するなどの理由で合流先が存在しない場合は、実行経路pの中で要素nの後に要素nと同階層で出現する要素n以降をステップS57の判定対象とする。なお、実行経路pの中に関数gが呼び出された要素nより後で要素nと同階層の要素がない場合は、ステップS57の判定結果をNOとしてステップS61に進む。 However, the path of the error handling resource release function, there is a possibility that even the variable r after the function g is called is used, the point you think that the error handling of the resource release function skip determining. Specifically, the extraction unit 13 in the execution path p, after the element n j, locate the first occurrence of the branch in element n j the same level, if a branch is present in the execution path p its a merging destination element n h and subsequent elements of the branch and determination target in step S57. Also, if the merge destination because of a program in the middle of the case and branches branch does not exist and ends not exist, element n appearing after the element n j in execution path p in element n j the same level After h is set as the determination target in step S57. If there is no later elements n j in the same hierarchical elements than the function g is called element n j in the execution path p, the process proceeds to step S61 of the determination result of the step S57 as NO.

一方、実行経路p上で関数gが呼び出されていない場合の(ステップS55のNO)、実行経路pがリソース捕捉関数のエラー処理の経路であるか否かの判定は、実行経路pで変数rが使用されているか判定することで行う(ステップS58)。具体的には、実行経路pの中で、先頭の要素nの後に、要素nと同階層で最初に出現する分岐を探し、分岐が存在する場合は、分岐が出現する要素を要素nh’とし、分岐が存在しない場合は、要素nを要素nh’とする。そして、実行経路pの要素nh’の次の要素から最後の要素nまでのいずれかの要素に対応する箇所で、変数rが使用されているか調べる。 On the other hand, when the function g is not called on the execution path p (NO in step S55), it is determined whether or not the execution path p is an error processing path of the resource capturing function by using the variable r in the execution path p. This is performed by determining whether or not is used (step S58). Specifically, in the execution path p, after the first element n 1 of the element n 1 and locate the first occurrence branch at the same hierarchy, if the branch is present, component elements n of branching appears If h ′ and there is no branch, element n 1 is element n h ′ . Then, at a location corresponding to one element of the following elements up to the last element n m elements n h 'execution path p, checks whether the variable r is used.

変数rが使用されている場合は(ステップS58のYES)、補足後使用区間調査フラグをfalseに設定する(ステップS60)。   If the variable r is used (YES in step S58), the post-supplemented used section survey flag is set to false (step S60).

変数rが使用されていない場合(ステップS58のNO)、リソース捕捉関数のエラー処理の経路であるとして捕捉失敗候補経路数を1加算する(ステップS59)。   If the variable r is not used (NO in step S58), the number of acquisition failure candidate paths is incremented by 1 (step S59) as an error processing path of the resource acquisition function.

ステップS54〜S59の処理で、関数f,gと変数rの出現パタンの検査が終了すると、補足後使用区間調査フラグがtrueである場合は、好適経路数を1加算する(ステップS61)。なお、実行経路pがリソース捕捉関数のエラー処理の経路であるときもパタンに当てはまるので好適経路数は1加算される。つまり、実行経路pがリソース捕捉関数のエラー処理の経路であるときは捕捉失敗候補経路数と好適経路数がそれぞれ1加算される。   When the inspection of the appearance patterns of the functions f and g and the variable r is completed in the processes of steps S54 to S59, if the post-supplemented used section survey flag is true, the number of suitable routes is incremented by 1 (step S61). It should be noted that when the execution path p is an error processing path of the resource capturing function, it is also applied to the pattern, so that the number of suitable paths is incremented by 1. That is, when the execution path p is an error processing path of the resource capture function, 1 is added to each of the number of acquisition failure candidate paths and the number of suitable paths.

全ての実行経路p∈PについてステップS53〜S61を処理すると(ステップS62)、全ての実行経路p∈Pにおいて関数f,gと変数rが図9のパタンに当てはまるときは、関数f,gと変数rがリソース捕捉関数、リソース解放関数、およびリソース格納変数である可能性はポジティブであると判定する(ステップS63)。具体的には、抽出部13は、実行経路集合Pが含む実行経路数|P|が好適経路数と一致し、好適経路数>捕捉失敗好適経路数であれば、ポジティブと判定する。 When steps S53 to S61 are processed for all the execution paths pεP (step S62), when the functions f and g and the variable r apply to the pattern of FIG. 9 in all the execution paths pεP, the functions f and g The possibility that the variable r is a resource capture function, a resource release function, and a resource storage variable is determined to be positive (step S63). Specifically, the extraction unit 13 determines positive if the number of execution paths | P | included in the execution path set P coincides with the number of suitable paths, and the number of suitable paths> the number of capture failure suitable paths.

以上の図10,11の処理により、リソース捕捉関数とリソース解放関数である可能性が高い関数ペアを抽出することができる。例えば、図4のソースコードからは、関数ペア集合={(mempool_alloc,mempool_free),(mempool_alloc,finish)}が得られる。このうち関数ペア(mempool_alloc,finish)は、本来抽出したい関数ペアではないが、finishの中でmempool_freeが呼び出されており、上記で説明したアルゴリズムに適合して抽出されるペアである(false positive)。検出部14が誤り検出処理を行う前に、抽出された関数ペアを人が精査してfalse positiveの関数ペアを取り除いてもよい。 10 and 11 can extract a function pair that is highly likely to be a resource capture function and a resource release function. For example, from the source code of FIG. 4, a function pair set = {(mpmool_alloc, mempool_free), (mmpool_aloc, finish)} is obtained. Of these, the function pair (mempool_alloc, finish) is not a function pair that is originally desired to be extracted, but mempool_free is called in the finish, and is a pair extracted in conformity with the algorithm described above (false positive). . Before the detection unit 14 performs the error detection process, a person may carefully examine the extracted function pair and remove the false positive function pair.

また、図4のソースコード中のmempool_constructor関数とmempool_destructor関数もリソース捕捉関数とリソース解放関数であるが、本アルゴリズムに適合しなかったために抽出されていない。これは、図4のソースコードにはmempool_constructor関数で捕捉したリソースが使われない実行経路が存在するので、図11のステップS56の判定に適合しないためである。ステップS56の判定処理を省略すれば、mempool_constructor関数とmempool_destructor関数が抽出されるが、false positiveが多くなることが見込まれる。 In addition, the mempool_constructor function and mempool_destructor function in the source code of FIG. 4 are also a resource capture function and a resource release function, but are not extracted because they did not conform to this algorithm. This is because the source code in FIG. 4 does not conform to the determination in step S56 in FIG. 11 because there is an execution path in which the resource captured by the mempool_constructor function is not used. If the determination process of step S56 is omitted, the mempool_constructor function and the mempool_destructor function are extracted, but it is expected that the false positive will increase.

以上説明したように、本実施の形態によれば、入力したソースコードに現れる異なる2つの関数f,gの全ての組み合わせについて、関数fを呼び出している行番号kを全て挙げて、関数fを呼び出した行番号k以降の実行経路の全てにおいて、関数fの返却値を格納する変数rと関数gが一般的なリソース格納変数と一般的なリソース解放関数の出現パタンに当てはまるときは、関数f,gをリソース捕捉関数とリソース解放関数として抽出し、リソース捕捉関数が捕捉したリソースを未初期化で参照している箇所を検出することにより、静的コード解析により、ユーザの定義したリソース捕捉関数とリソース解放関数の使い方の誤りを検出することが可能となる。例えば、ミドルウェアや基盤機能として開発したリソース捕捉解放APIの利用時の未初期化リソースを参照する誤りを検出することが可能となる。 As described above, according to the present embodiment, for all combinations of two different functions f and g appearing in the input source code, all the line numbers k that call the function f are listed, and the function f is When the variables r and g for storing the return value of the function f apply to the general resource storage variable and the appearance pattern of the general resource release function in all the execution paths after the called line number k, the function f , G are extracted as a resource capture function and a resource release function, and a resource capture function defined by the user is obtained by static code analysis by detecting a location where a resource captured by the resource capture function is referenced without being initialized. It is possible to detect errors in the usage of the resource release function. For example, it is possible to detect an error referring to an uninitialized resource when using a resource capture / release API developed as middleware or a basic function.

1…ソースコード検査装置
11…入力部
12…解析部
13…抽出部
14…検出部
DESCRIPTION OF SYMBOLS 1 ... Source code inspection apparatus 11 ... Input part 12 ... Analysis part 13 ... Extraction part 14 ... Detection part

Claims (6)

リソースを捕捉するリソース捕捉関数と前記リソースを解放するリソース解放関数をソースコードから抽出するプログラム解析装置であって、
ソースコードを入力する入力手段と、
前記ソースコードに現れる異なる2つの第1関数と第2関数を選択し、ソースコード上で前記第1関数が呼び出された位置から辿ることのできる実行経路の全てにおいて、前記第1関数の返却値を格納する変数の参照状況と前記第2関数の呼出し状況が一般的なリソース格納変数と一般的なリソース解放関数の用いられ方に当てはまる場合は、前記第1関数と前記第2関数のそれぞれをリソース捕捉関数とリソース解放関数として抽出する抽出手段と、を有し、
前記一般的なリソース格納変数と一般的なリソース解放関数の用いられ方は、リソース捕捉関数が呼び出された後の実行経路において前記リソース解放関数の呼出し回数は1回以内であって、前記実行経路において前記リソース解放関数が呼び出されないときは、前記実行経路には前記リソース捕捉関数が呼び出された後に分岐があり、当該分岐の後は前記リソース格納変数が参照されていないものであり、前記実行経路において前記リソース解放関数が呼び出されているときは、前記リソース解放関数が呼び出された後の分岐の合流後は前記リソース格納変数が参照されていないことを特徴とするプログラム解析装置。
A program analysis device for extracting a resource capture function for capturing a resource and a resource release function for releasing the resource from a source code,
An input means for inputting source code;
Two different first functions and second functions appearing in the source code are selected, and the return value of the first function in all the execution paths that can be traced from the position where the first function is called on the source code. If the reference status of the variable storing the variable and the call status of the second function apply to the general usage of the resource storage variable and the general resource release function, the first function and the second function are An extraction means for extracting as a resource capture function and a resource release function ,
The general resource storage variable and the general resource release function are used in such a way that the number of calls of the resource release function is within one in the execution path after the resource capture function is called, and the execution path When the resource release function is not called in step 1, the execution path has a branch after the resource capture function is called, and the resource storage variable is not referenced after the branch, and the execution path When the resource release function is called in a route, the resource storage variable is not referred to after the branch merges after the resource release function is called .
請求項1に記載のプログラム解析装置と、
前記プログラム解析装置が抽出したリソース捕捉関数により捕捉されたリソースが未初期化のまま参照されている箇所をソースコード上で検出する検出手段と、
を有することを特徴とする誤り検出装置。
A program analysis device according to claim 1 ;
Detecting means for detecting a location on the source code where the resource captured by the resource capturing function extracted by the program analysis device is referred to without being initialized;
An error detection apparatus comprising:
リソースを捕捉するリソース捕捉関数と前記リソースを解放するリソース解放関数をソースコードから抽出する、コンピュータにより実行されるプログラム解析方法であって、
ソースコードを入力するステップと、
前記ソースコードに現れる異なる2つの第1関数と第2関数を選択し、ソースコード上で前記第1関数が呼び出された位置から辿ることのできる実行経路の全てにおいて、前記第1関数の返却値を格納する変数の参照状況と前記第2関数の呼出し状況が一般的なリソース格納変数と一般的なリソース解放関数の用いられ方に当てはまる場合は、前記第1関数と前記第2関数のそれぞれをリソース捕捉関数とリソース解放関数として抽出するステップと、を有し、
前記一般的なリソース格納変数と一般的なリソース解放関数の用いられ方は、リソース捕捉関数が呼び出された後の実行経路において前記リソース解放関数の呼出し回数は1回以内であって、前記実行経路において前記リソース解放関数が呼び出されないときは、前記実行経路には前記リソース捕捉関数が呼び出された後に分岐があり、当該分岐の後は前記リソース格納変数が参照されていないものであり、前記実行経路において前記リソース解放関数が呼び出されているときは、前記リソース解放関数が呼び出された後の分岐の合流後は前記リソース格納変数が参照されていないことを特徴とするプログラム解析方法。
A computer-executed program analysis method for extracting a resource capture function for capturing a resource and a resource release function for releasing the resource from source code,
Input source code,
Two different first functions and second functions appearing in the source code are selected, and the return value of the first function in all the execution paths that can be traced from the position where the first function is called on the source code. If the reference status of the variable storing the variable and the call status of the second function apply to the general usage of the resource storage variable and the general resource release function, the first function and the second function are Extracting as a resource capture function and a resource release function ,
The general resource storage variable and the general resource release function are used in such a way that the number of calls of the resource release function is within one in the execution path after the resource capture function is called, and the execution path When the resource release function is not called in step 1, the execution path has a branch after the resource capture function is called, and the resource storage variable is not referenced after the branch, and the execution path When the resource release function is called in a route, the resource storage variable is not referred to after the branch merges after the resource release function is called .
コンピュータにより実行される誤り検出方法であって、
請求項3に記載のプログラム解析方法によりリソース捕捉関数を抽出するステップと、
前記リソース捕捉関数により捕捉されたリソースが未初期化のまま参照されている箇所をソースコード上で検出するステップと、
を有することを特徴とする誤り検出方法。
An error detection method executed by a computer,
Extracting a resource capture function by the program analysis method according to claim 3 ;
Detecting on the source code where the resource captured by the resource capturing function is referenced without being initialized;
An error detection method comprising:
請求項1に記載のプログラム解析装置の各手段としてコンピュータを動作させることを特徴とするプログラム解析プログラム。 A program analysis program for operating a computer as each means of the program analysis apparatus according to claim 1 . 請求項2に記載の誤り検出装置の各手段としてコンピュータを動作させることを特徴とする誤り検出プログラム。 An error detection program for causing a computer to operate as each means of the error detection apparatus according to claim 2 .
JP2015028456A 2015-02-17 2015-02-17 Program analysis device, error detection device, program analysis method, error detection method, program analysis program, and error detection program Active JP6301851B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2015028456A JP6301851B2 (en) 2015-02-17 2015-02-17 Program analysis device, error detection device, program analysis method, error detection method, program analysis program, and error detection program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2015028456A JP6301851B2 (en) 2015-02-17 2015-02-17 Program analysis device, error detection device, program analysis method, error detection method, program analysis program, and error detection program

Publications (2)

Publication Number Publication Date
JP2016151855A JP2016151855A (en) 2016-08-22
JP6301851B2 true JP6301851B2 (en) 2018-03-28

Family

ID=56696624

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2015028456A Active JP6301851B2 (en) 2015-02-17 2015-02-17 Program analysis device, error detection device, program analysis method, error detection method, program analysis program, and error detection program

Country Status (1)

Country Link
JP (1) JP6301851B2 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR102004592B1 (en) * 2016-12-13 2019-07-26 경북대학교 산학협력단 Device for formal verification of automotive control software and methods, recording medium for performing the method
CN111104121B (en) * 2019-12-20 2023-05-16 抖音视界有限公司 Detection method, detection device, detection equipment and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4257096B2 (en) * 2002-10-21 2009-04-22 株式会社日立製作所 Static analysis device for source program
JP2006127496A (en) * 2004-10-01 2006-05-18 Matsushita Electric Ind Co Ltd Device and method for api specification verification, program for executing the same, and storage medium for storing the same

Also Published As

Publication number Publication date
JP2016151855A (en) 2016-08-22

Similar Documents

Publication Publication Date Title
CN109426723B (en) Detection method, system, equipment and storage medium using released memory
US7971193B2 (en) Methods for performining cross module context-sensitive security analysis
CN101661543B (en) Method and device for detecting security flaws of software source codes
CN109359468B (en) Vulnerability detection method, device and equipment
CN111104335B (en) C language defect detection method and device based on multi-level analysis
JP2019204482A (en) Concurrency vulnerability detection
Zhang et al. Ripple: Reflection analysis for android apps in incomplete information environments
JP5303795B2 (en) Application analysis method, analysis system, and analysis program
JP6245006B2 (en) Test case generation apparatus, method, and program
Wu et al. Simulee: Detecting cuda synchronization bugs via memory-access modeling
JP6301851B2 (en) Program analysis device, error detection device, program analysis method, error detection method, program analysis program, and error detection program
CN106681904B (en) Method and device for analyzing coverage rate of test piece and coverage application interface
US11262994B2 (en) Method and device for identifying type of variable in binary
CN117633808A (en) Method, processor and machine-readable storage medium for vulnerability detection
Xiao et al. Embedding code contexts for cryptographic api suggestion: New methodologies and comparisons
US11657160B2 (en) Vulnerability analyzer
KR102314829B1 (en) Method for evaluating risk of data leakage in application, recording medium and device for performing the method
Borodin et al. Deterministic static analysis
JP2017037387A (en) Program analysis device, program analysis method and program analysis program
JP2017041196A (en) Stub object determination device, method, and program
JP6574151B2 (en) Program analysis apparatus, program analysis method, and program analysis program
Omotunde et al. A framework to reduce redundancy in android test suite using refactoring
CN113407442B (en) Pattern-based Python code memory leak detection method
CN115130111B (en) System operation vulnerability restoration method based on AI analysis and big data service system
WO2022079779A1 (en) Detection device and detection program

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20170213

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20171115

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20180109

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20180215

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20180227

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20180301

R150 Certificate of patent or registration of utility model

Ref document number: 6301851

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150