JP2011133966A - Device and method for analyzing program - Google Patents

Device and method for analyzing program Download PDF

Info

Publication number
JP2011133966A
JP2011133966A JP2009290612A JP2009290612A JP2011133966A JP 2011133966 A JP2011133966 A JP 2011133966A JP 2009290612 A JP2009290612 A JP 2009290612A JP 2009290612 A JP2009290612 A JP 2009290612A JP 2011133966 A JP2011133966 A JP 2011133966A
Authority
JP
Japan
Prior art keywords
code
analysis
variable
bug
value
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.)
Granted
Application number
JP2009290612A
Other languages
Japanese (ja)
Other versions
JP5343840B2 (en
Inventor
Kazuya Segawa
和也 瀬川
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.)
Fujitsu Ltd
Original Assignee
Fujitsu Ltd
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 Fujitsu Ltd filed Critical Fujitsu Ltd
Priority to JP2009290612A priority Critical patent/JP5343840B2/en
Publication of JP2011133966A publication Critical patent/JP2011133966A/en
Application granted granted Critical
Publication of JP5343840B2 publication Critical patent/JP5343840B2/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

<P>PROBLEM TO BE SOLVED: To provide a technology for obtaining a detailed analysis result of a computer program. <P>SOLUTION: An analysis device for the program obtains codes of the computer program, sets a code of a part including a variable of the obtained codes as an analysis target, decides possibility of a bug by whether the code of the analysis target satisfies a prescribed static analysis condition, inserts an acquisition code for acquiring a value of the variable included in the code of the analysis target decided that it has the possibility of the bug into the program, executes the program, and decides the bug by whether the code of the analysis target satisfies a prescribed dynamic analysis condition when substituting the value obtained by the acquisition code for the variable. <P>COPYRIGHT: (C)2011,JPO&INPIT

Description

本件は、プログラムを解析する技術に関する。   This case relates to a technique for analyzing a program.

プログラムのバグを検出するツールの一つとして、静的解析ツールがある。静的解析手法は、解析対象のコードを実行する必要がなく、また、テストケースを作成する必要が無い、大規模で複雑なコードの解析が可能といった利点がある。   One of the tools for detecting program bugs is a static analysis tool. The static analysis method has an advantage that it is possible to analyze a large-scale and complicated code without having to execute a code to be analyzed and without creating a test case.

また、先行技術としては、以下の特許文献が存在する。   Moreover, the following patent documents exist as prior art.

特開平9−26897号公報JP-A-9-26897

静的解析ツールは、ソースコードにバグとなる形式が含まれていれば、バグの可能性を指摘するが、実際にエラーとなるか否かは判断できない場合がある。
[例1]
char a[5];
char b[10]
strcpy(b, "123456789");
strcpy(a, b);
Static analysis tools point out the possibility of a bug if the source code contains a buggy format, but it may not be possible to determine whether or not an error actually occurs.
[Example 1]
char a [5];
char b [10]
strcpy (b, "123456789");
strcpy (a, b);

[例1]のプログラムでは、1行目で変数aのサイズを5、2行目で変数bのサイズを10と定義し、4行目で変数bの値を変数aにコピーしているので、静的解析ツールは、以下のように指摘メッセージを出力する。   In the program of [Example 1], the size of the variable a is defined as 5 in the first line, the size of the variable b is defined as 10 in the second line, and the value of the variable b is copied to the variable a in the fourth line. The static analysis tool outputs an indication message as follows.

[指摘メッセージ]
pgr0532 strcpy(a, b) は領域 a を超えてコピーしてしまう可能性があります。(複写先 : a, 複写元 : b)
静的解析ツールは、strcpy関数のように、領域から領域にデータをコピーする関数について、コピー元の領域(変数b)のサイズとコピー先(変数a)の領域のサイズを比較し、コピー先の領域のサイズの方が小さい場合に上記[指摘メッセージ]を出力する。
[Indication message]
pgr0532 strcpy (a, b) may copy beyond area a. (Copy destination: a, Copy source: b)
The static analysis tool compares the size of the copy source area (variable b) with the size of the copy destination (variable a) area for a function that copies data from area to area, such as the strcpy function. The above [pointing message] is output when the size of the area is smaller.

[例1]のプログラムでは、4行目で"123456789"を変数bにコピーしているので、5
行目のstrcpy(a, b)でコピーする値が変数Aのサイズを超えるためバグとなる。
In the program of [Example 1], "123456789" is copied to variable b in the 4th line, so 5
A bug occurs because the value copied by strcpy (a, b) on the line exceeds the size of variable A.

一方、[例2]のプログラムでは、4行目で"123"を変数bにコピーしているので、5
行目のstrcpy(a, b)でコピーする値が変数Aのサイズを超えないためバグとならない。
On the other hand, in the program of [Example 2], “123” is copied to the variable b in the fourth line.
Since the value copied by strcpy (a, b) on the line does not exceed the size of variable A, there is no bug.

[例2]
char a[5];
char b[10]
strcpy(b, "123");
strcpy(a, b);
[Example 2]
char a [5];
char b [10]
strcpy (b, "123");
strcpy (a, b);

静的解析ではプログラムを実際に動作させないので、実値を求めることはできず、静的解析ツールは、例1又は例2のケースで実際にバグとなるか否かまで解析することができない。   Since the program is not actually operated in the static analysis, the actual value cannot be obtained, and the static analysis tool cannot analyze whether or not a bug actually occurs in the case of Example 1 or Example 2.

そこで、開示の一形態は、コンピュータプログラムの詳細な解析結果を得る技術を提供する。   Therefore, one form of the disclosure provides a technique for obtaining a detailed analysis result of a computer program.

開示の一実施形態としての解析装置は、
コンピュータプログラムのコードを取得する取得部と、
取得した前記コードのうち、変数を含む部分のコードを解析対象とし、当該解析対象のコードが所定の静的解析条件を満たすか否かによってバグの可能性を判定する静的解析部と、
前記バグの可能性があると判定された解析対象のコードに含まれる前記変数の値を取得する取得コードを前記プログラムに挿入する挿入部と、
前記プログラムを実行し、前記取得コードによって取得した値を前記変数に代入した場合に前記解析対象のコードが所定の動的解析条件を満たすか否かによってバグを判定する動的解析部と、を備えた。
An analysis apparatus as an embodiment of the disclosure is:
An acquisition unit for acquiring a code of a computer program;
Of the acquired code, a static analysis unit that determines the possibility of a bug depending on whether or not a code including a variable includes a variable and the analysis target code satisfies a predetermined static analysis condition;
An insertion unit that inserts into the program an acquisition code for acquiring the value of the variable included in the code to be analyzed that is determined to have the possibility of the bug;
A dynamic analysis unit that executes the program and determines a bug based on whether or not the analysis target code satisfies a predetermined dynamic analysis condition when the value acquired by the acquisition code is substituted into the variable; Prepared.

開示の一実施形態は、コンピュータプログラムの詳細な解析結果を得る技術を提供する。   One embodiment of the disclosure provides a technique for obtaining a detailed analysis result of a computer program.

解析装置の構成図Configuration diagram of analyzer 解析方法の全体のフローを示す図Diagram showing overall flow of analysis method サンプルプログラムを示す図Diagram showing sample program 静的解析処理の説明図Illustration of static analysis processing 取得コードの挿入処理の説明図Explanatory drawing of the acquisition code insertion process 動的解析処理の説明図Illustration of dynamic analysis processing 動的解析処理のテストケースの説明図Illustration of test cases for dynamic analysis processing 出力処理の説明図Illustration of output processing 解析結果を示す図Figure showing analysis results 解析結果を示す図Figure showing analysis results 挿入内容DBの一例を示す図The figure which shows an example of insertion content DB 挿入内容DBの一例を示す図The figure which shows an example of insertion content DB 挿入内容DBの一例を示す図The figure which shows an example of insertion content DB 挿入内容DBの一例を示す図The figure which shows an example of insertion content DB 挿入内容DBの一例を示す図The figure which shows an example of insertion content DB

以下、図面を参照して本発明を実施するための形態について説明する。以下の実施の形態の構成は例示であり、本発明は実施の形態の構成に限定されない。   Hereinafter, embodiments for carrying out the present invention will be described with reference to the drawings. The configuration of the following embodiment is an exemplification, and the present invention is not limited to the configuration of the embodiment.

<装置構成の説明>
本実施形態の解析装置は、コンピュータプログラムを静的解析し、その静的解析で検出したバグの可能性の真偽を、動的テストを実施することで証明する。図1は本発明のシステム構成図である。
<Description of device configuration>
The analysis apparatus according to the present embodiment statically analyzes a computer program and proves the possibility of a bug detected by the static analysis by performing a dynamic test. FIG. 1 is a system configuration diagram of the present invention.

解析装置1は、図1に示すように、データの演算処理を行うデータ処理部11と、他の
装置との通信を行う通信処理部12、演算処理の為のデータやソフトウェアを記憶する記憶部(ハードディスク)13、入力部14、出力部15を備えたコンピュータである。
As shown in FIG. 1, the analysis device 1 includes a data processing unit 11 that performs data arithmetic processing, a communication processing unit 12 that performs communication with other devices, and a storage unit that stores data and software for arithmetic processing. The computer includes a (hard disk) 13, an input unit 14, and an output unit 15.

通信処理部12は、ネットワークやケーブル等の回線を介して他のコンピュータとの通信を行う。   The communication processing unit 12 communicates with another computer via a network or a line such as a cable.

記憶部13は、オペレーティングシステム(OS)やアプリケーションプログラム(解析プログラム)を記憶している。また、記憶部13は、解析対象のプログラムや、解析処理に用いるデータベースも記憶している。   The storage unit 13 stores an operating system (OS) and application programs (analysis programs). The storage unit 13 also stores a program to be analyzed and a database used for analysis processing.

入力部14は、データ処理部11へ情報を入力する手段であり、キーボードやポインティングデバイスといったユーザインタフェースや、メモリカードやCD−ROM等の記憶媒体から情報を読み取るデバイスを有する。   The input unit 14 is a means for inputting information to the data processing unit 11, and includes a user interface such as a keyboard and a pointing device, and a device that reads information from a storage medium such as a memory card or a CD-ROM.

出力部15は、データ処理部11の処理結果を出力する手段であり、処理結果等を表示する表示装置や、データを印刷するプリンターを有する。   The output unit 15 is a unit that outputs the processing result of the data processing unit 11, and includes a display device that displays the processing result and a printer that prints data.

データ処理部11は、CPUやメインメモリを有し、前記OSやアプリケーションプログラムを記憶部13からメインメモリに読み出し、読み出したOSやアプリケーションプログラムに従ってCPUが演算処理を行う。この演算処理により、CPUは、取得部21や、静的解析部22、挿入部23、動的解析部24、出力処理部25、ビルド部26としても機能する。   The data processing unit 11 includes a CPU and a main memory, reads the OS and application programs from the storage unit 13 to the main memory, and the CPU performs arithmetic processing according to the read OS and application programs. With this calculation process, the CPU also functions as the acquisition unit 21, the static analysis unit 22, the insertion unit 23, the dynamic analysis unit 24, the output processing unit 25, and the build unit 26.

データ処理部11のCPU、即ち取得部21は、バグの解析を行う対象であるコンピュータプログラムのコードを取得する。   The CPU of the data processing unit 11, that is, the acquisition unit 21 acquires the code of a computer program that is a target for bug analysis.

データ処理部11のCPU、即ち静的解析部22は、取得したコードのうち、変数を含む部分、例えば命令、ステップ、行といった所定単位のコードを解析対象とし、当該解析対象のコードが所定の静的解析条件を満たすか否かによってバグの可能性を判定する。静的解析条件は、記憶部13内の静的条件データベース(DB)に記憶されており、解析対象のコードに応じた条件が適宜呼び出される。   The CPU of the data processing unit 11, that is, the static analysis unit 22 analyzes a predetermined unit code such as a part including a variable, for example, an instruction, a step, and a line, among the acquired codes, and the analysis target code is a predetermined code. The possibility of a bug is determined by whether or not the static analysis condition is satisfied. The static analysis condition is stored in a static condition database (DB) in the storage unit 13, and a condition corresponding to the analysis target code is appropriately called.

静的解析条件は、例えば、解析対象のコードに含まれる関数に必須のパラメータが記述されているか、パラメータに設定されている変数の型が正しいかといった命令の構文が正しいか否かであっても良い。   The static analysis condition is, for example, whether or not the required parameter is described in the function included in the analysis target code, or whether the syntax of the instruction is correct, such as whether the variable type set in the parameter is correct. Also good.

また、静的解析条件は、独立行政法人 情報処理推進機構 ソフトウェア・エンジニアリング・センターによって策定された 「組み込みソフトウェア開発者向け コーディング作法ガイド」に適合しているかどうかであっても良い。更に、静的解析条件は、MISRA(Motor Industry Software Reliability Associationk)のガイドラインに適合しているかど
うかであっても良い。
In addition, the static analysis condition may be whether or not it conforms to the “Coding Practice Guide for Embedded Software Developers” formulated by the Information Technology Promotion Organization Software Engineering Center. Further, the static analysis condition may be whether or not it conforms to MISRA (Motor Industry Software Reliability Associationk) guidelines.

特に本実施形態では、代入先の変数のサイズが代入元の変数のサイズよりも大きい、0となる可能性がある変数で除算しているか等、変数を用いた処理を行った際に、変数の値によって誤りや矛盾が生じるか否かが、静的解析条件として含まれる。この条件を満たさなければ、変数の値によって誤りや矛盾が発生する可能性があり、解析装置1は動的解析が必要と判定できる。   In particular, in the present embodiment, when processing using a variable is performed, such as whether the size of the variable at the assignment destination is larger than the size of the variable at the assignment source or is divided by a variable that may be 0, the variable Whether or not an error or contradiction occurs depending on the value of is included as a static analysis condition. If this condition is not satisfied, an error or contradiction may occur depending on the value of the variable, and the analysis apparatus 1 can determine that dynamic analysis is necessary.

データ処理部11のCPU、即ち挿入部23は、バグの可能性があると判定された解析対象のコードに含まれる変数の値を取得する取得コードを前記プログラムに挿入する。   The CPU of the data processing unit 11, that is, the insertion unit 23 inserts into the program an acquisition code that acquires the value of a variable included in the analysis target code that is determined to have a bug.

データ処理部11のCPU、即ち動的解析部24は、プログラムを実行し、取得コードによって取得した値を解析対象のコードの変数に代入した場合に当該コードが所定の動的解析条件を満たすか否かによってバグを判定する。   The CPU of the data processing unit 11, that is, the dynamic analysis unit 24 executes the program, and if the value acquired by the acquired code is substituted for the variable of the code to be analyzed, does the code satisfy a predetermined dynamic analysis condition? Judge bugs based on whether or not.

データ処理部11のCPU、即ち出力処理部25は、静的解析部22や動的解析部24の判定結果を取得し、この判定結果に基づいてメッセージや証明書を表示部やプリンター等の出力部15から出力させる。   The CPU of the data processing unit 11, that is, the output processing unit 25 acquires the determination results of the static analysis unit 22 and the dynamic analysis unit 24, and outputs a message or certificate based on the determination results to a display unit, a printer, or the like. Output from the unit 15.

データ処理部11のCPU、即ちビルド部26は、コンピュータプログラムのコードのコンパイルやライブラリのリンクといった処理、所謂ビルドを行い、実行可能ファイルを作成する。   The CPU of the data processing unit 11, that is, the build unit 26 performs a process such as compiling code of a computer program and linking a library, so-called build, and creates an executable file.

なお、本例の解析装置1の構成要素のうち、情報を処理する要素は、汎用のプロセッサがソフトウェアとしての解析プログラムを実行することによって、上記各機能を実現するものである。これら情報を処理する要素の一部或いは全部は、基本的な回路を組み合わせて各々の機能を実現したハードウェアであっても良い。   Note that, among the components of the analysis apparatus 1 of this example, the elements that process information realize the functions described above when a general-purpose processor executes an analysis program as software. Some or all of the elements that process these pieces of information may be hardware that realizes each function by combining basic circuits.

本例の解析装置1において、取得部21や、静的解析部22、挿入部23、動的解析部24、出力処理部25、ビルド部26が、前記情報を処理する要素である。   In the analysis apparatus 1 of this example, the acquisition unit 21, the static analysis unit 22, the insertion unit 23, the dynamic analysis unit 24, the output processing unit 25, and the build unit 26 are elements that process the information.

これら情報を処理する要素であるハードウェアは、例えば、FPGA[Field Programmable Gate Array]、ASIC[Application Specific Integrated Circuit]、LSI[Large Scale Integration]といった基本的な回路を備えても良い。また、当該ハードウ
ェアは、IC[Integrated Circuit]、ゲートアレイ、論理回路、信号処理回路、アナログ回路といった基本的な回路を備えても良い。
The hardware that is an element for processing these pieces of information may include basic circuits such as an FPGA (Field Programmable Gate Array), an ASIC (Application Specific Integrated Circuit), and an LSI (Large Scale Integration). The hardware may include basic circuits such as an IC [Integrated Circuit], a gate array, a logic circuit, a signal processing circuit, and an analog circuit.

論理回路としては、例えば、AND、OR、NOT、NAND、NOR、フリップフロップ、カウンタ回路がある。信号処理回路には、信号値に対し、例えば、加算、乗算、除算、反転、積和演算、微分、積分を実行する回路が、含まれていてもよい。アナログ回路には、例えば、信号値に対して、増幅、加算、乗算、微分、積分を実行する回路が、含まれていてもよい。   Examples of the logic circuit include AND, OR, NOT, NAND, NOR, flip-flop, and counter circuit. The signal processing circuit may include a circuit that performs, for example, addition, multiplication, division, inversion, product-sum operation, differentiation, and integration on the signal value. The analog circuit may include, for example, a circuit that performs amplification, addition, multiplication, differentiation, and integration on the signal value.

<解析方法の説明>
図2は、本実施形態の解析装置1が解析プログラムに従って実行する解析方法の説明図である。
<Description of analysis method>
FIG. 2 is an explanatory diagram of an analysis method executed by the analysis apparatus 1 according to the present embodiment according to the analysis program.

オペレータが解析対象のプログラムを指定し、解析プログラムの実行を指示すると、解析装置1の取得部21は、解析対象であるプログラムのソースコードを取得する(S1)。例えば、解析対象であるプログラムが記憶部13に記憶されている場合、取得部21は記憶部13から当該プログラムのコードを順次読み出し、メインメモリに展開する。また、解析対象であるプログラムがCDやDVD等の記憶媒体に記憶されている場合、取得部21は入力部14に挿入された記憶媒体から当該プログラムのコードを読み出しても良い。更に取得部21は、通信処理部12を介して他のコンピュータから解析対象であるプログラムのコードを取得(受信)しても良い。   When the operator designates the analysis target program and instructs the execution of the analysis program, the acquisition unit 21 of the analysis apparatus 1 acquires the source code of the analysis target program (S1). For example, when a program to be analyzed is stored in the storage unit 13, the acquisition unit 21 sequentially reads out the code of the program from the storage unit 13 and develops it in the main memory. When the analysis target program is stored in a storage medium such as a CD or DVD, the acquisition unit 21 may read the code of the program from the storage medium inserted in the input unit 14. Further, the acquisition unit 21 may acquire (receive) the code of the program to be analyzed from another computer via the communication processing unit 12.

静的解析部22は、取得したコードのうち、変数を含む命令を解析対象とし、当該解析対象の命令が所定の静的解析条件を満たすか否かによってバグの可能性があるか否かを判定する(S2)。   The static analysis unit 22 sets an instruction including a variable in the acquired code as an analysis target, and determines whether or not there is a possibility of a bug depending on whether or not the analysis target instruction satisfies a predetermined static analysis condition. Determine (S2).

バグの可能性があると判定された場合(S2,Yes)、挿入部23は、解析対象のコードに含まれる変数の値を取得する取得コードを記憶部13内の挿入内容データベース(DB)から読み出してプログラムのソースコードに挿入する(S3)。   When it is determined that there is a possibility of a bug (S2, Yes), the insertion unit 23 obtains an acquisition code for acquiring a value of a variable included in the analysis target code from an insertion content database (DB) in the storage unit 13. Read and insert into the source code of the program (S3).

ビルド部26は、S3で取得コードを挿入したソースコードをビルドし、実行可能なファイル(実行モジュール)を作成する(S4)。   The build unit 26 builds the source code into which the acquired code is inserted in S3, and creates an executable file (execution module) (S4).

そして、動的解析部25は、S4で作成した実行モジュールを実行し、取得コードによって取得した値が所定の動的解析条件を満たすか否かによってバグを判定する(S5)。   Then, the dynamic analysis unit 25 executes the execution module created in S4, and determines a bug depending on whether or not the value acquired by the acquisition code satisfies a predetermined dynamic analysis condition (S5).

動的解析後、出力処理部25は、S2における静的解析結果およびS5における動的解析結果を出力部15から出力させる(S6)。   After the dynamic analysis, the output processing unit 25 causes the output unit 15 to output the static analysis result in S2 and the dynamic analysis result in S5 (S6).

なお、静的解析ステップS2、取得コードの挿入ステップS3、動的解析ステップS5、解析結果の出力ステップS6は、以下で詳述される。   The static analysis step S2, the acquisition code insertion step S3, the dynamic analysis step S5, and the analysis result output step S6 will be described in detail below.

図3は、解析対象のプログラムの一例を示す図、図4は、静的解析ステップの説明図である。   FIG. 3 is a diagram illustrating an example of a program to be analyzed, and FIG. 4 is an explanatory diagram of a static analysis step.

静的解析部22は、S1で取得したソースコードの各命令について、命令に応じた静的解析条件を記憶部13或いはメモリから読み出し(S11)、当該命令が静的解析条件を満たしているか否かを判定する(S12)。   For each instruction of the source code acquired in S1, the static analysis unit 22 reads a static analysis condition corresponding to the instruction from the storage unit 13 or the memory (S11), and whether or not the instruction satisfies the static analysis condition. Is determined (S12).

例えば、図3のプログラムでは、7行目がstrcpy(a,b)であり、必要な引数が記述され
ているか、複写元のサイズが複写先のサイズを超えていないか、といった静的解析条件に適合しているかを判定する。なお、静的解析条件は、命令毎に書式や処理の内容に応じた条件が設定され、記憶部13或いはメモリに記憶されている。
For example, in the program of FIG. 3, the 7th line is strcpy (a, b), and the static analysis conditions such as whether the necessary arguments are described and whether the copy source size exceeds the copy destination size It is determined whether or not The static analysis conditions are set in accordance with the format and processing contents for each instruction, and stored in the storage unit 13 or the memory.

strcpy(a,b)は、複写元の変数bの値を複写先の変数aに複写する命令であるので、静
的解析部22は、変数bのサイズが変数aのサイズを超えていないかを判定する。図3では、1行目で変数aの値が5、2行目で変数bの値が10と設定されているので、静的解析部22は、7行目のstrcpy(a,b)について、バグの可能性があると判定する。
Since strcpy (a, b) is an instruction for copying the value of the copy source variable b to the copy destination variable a, the static analysis unit 22 determines whether the size of the variable b exceeds the size of the variable a. Determine. In FIG. 3, the value of the variable a is set to 5 in the first line, and the value of the variable b is set to 10 in the second line. Therefore, the static analysis unit 22 performs the strcpy (a, b) on the seventh line. Determine that there is a possible bug.

バグの可能性があると判定した場合(S12,No)、静的解析部22は、当該バグに応じた指摘メッセージを記憶部13から抽出し、静的解析の解析結果としてメモリに登録する(S13)。図5は、7行目のstrcpy(a,b)に応じて抽出される指摘メッセージの例
を示している。図5において、メッセージは発生する可能性があるバグの内容であり、指摘IDはメッセージを識別する情報である。
If it is determined that there is a possibility of a bug (S12, No), the static analysis unit 22 extracts an indication message corresponding to the bug from the storage unit 13 and registers it in the memory as an analysis result of the static analysis ( S13). FIG. 5 shows an example of an indication message extracted according to strcpy (a, b) on the seventh line. In FIG. 5, the message is the content of a bug that may occur, and the indication ID is information for identifying the message.

なお、静的解析部22は、指摘IDと静的解析条件とを対応づけて記憶しており、S12で満たしていないと判定した静的解析条件に対応する指摘IDで指摘メッセージを識別して記憶部13から抽出する。ここで静的解析条件は、発生する可能性があるバグとも対応しているので、S12で満たしていないと判定した静的解析条件に対応する指摘メッセージを抽出することで、発生する可能性があるバグに応じた静的解析条件が抽出できる。   The static analysis unit 22 stores the indication ID and the static analysis condition in association with each other, and identifies the indication message with the indication ID corresponding to the static analysis condition determined not to be satisfied in S12. Extracted from the storage unit 13. Here, since the static analysis condition also corresponds to a bug that may occur, there is a possibility that it will occur by extracting an indication message corresponding to the static analysis condition determined not to be satisfied in S12. Static analysis conditions according to a certain bug can be extracted.

図5は、図2における取得コードの挿入ステップS3の説明図である。
図2のS2で、バグの可能性があると判定された場合、挿入部23は静的解析の結果、即ちS2で抽出した指摘メッセージと対応する取得コードについて記憶部13の挿入内容DBを検索する(S21)。具体的には、挿入内容DBの各取得コードに、対応する指摘メッセージの指摘IDが付加されており、挿入部23は、S2で抽出した指摘メッセージ
の指摘IDと一致する指摘IDが付加された取得コードを検索する。
FIG. 5 is an explanatory diagram of the acquisition code insertion step S3 in FIG.
If it is determined in S2 in FIG. 2 that there is a possibility of a bug, the insertion unit 23 searches the insertion content DB of the storage unit 13 for the result of static analysis, that is, the acquired code corresponding to the indication message extracted in S2. (S21). Specifically, the indication ID of the corresponding indication message is added to each acquisition code of the insertion content DB, and the insertion unit 23 is added with the indication ID that matches the indication ID of the indication message extracted in S2. Search the acquisition code.

検索の結果、ヒットした取得コードがあれば(S22,Yes)、当該取得コードを挿入内容DBから取得し、ソースコードに挿入する。図15は、挿入内容DBから抽出した取得コードを含む情報の一例を示す図である。図15に示すように、挿入内容DBから抽出した情報50は、指摘ID51や、取得コード(trace)の挿入位置52、挿入内容53
、バグとなる条件(動的解析条件)54を含んでいる。挿入部23は、抽出した情報50の挿入位置52及び挿入内容53に基づき、バグの可能性が指摘された行(解析対象のコ
ード)の直前に取得コードを挿入する。また、取得コードの挿入位置は、解析対象のコー
ドの直前に限らず、直後であっても良い。取得コードの挿入位置は、取得コードと解析対象のコードとの間に当該解析対象のコードに含まれる変数の値を設定する命令が入らない位置であれば良い。
If there is a hit acquisition code as a result of the search (S22, Yes), the acquisition code is acquired from the insertion content DB and inserted into the source code. FIG. 15 is a diagram illustrating an example of information including an acquisition code extracted from the insertion content DB. As shown in FIG. 15, information 50 extracted from the insertion content DB includes an indication ID 51, an acquisition code (trace) insertion position 52, and an insertion content 53.
, A bug condition (dynamic analysis condition) 54 is included. Based on the insertion position 52 and the insertion content 53 of the extracted information 50, the insertion unit 23 inserts the acquired code immediately before the line (code to be analyzed) where the possibility of a bug is pointed out. Further, the acquisition code insertion position is not limited to immediately before the code to be analyzed, but may be immediately after. The insertion position of the acquisition code may be a position where an instruction for setting a value of a variable included in the analysis target code is not inserted between the acquisition code and the analysis target code.

図5は、図3のプログラムに取得コードを挿入した状態を示す図である。   FIG. 5 is a diagram showing a state where an acquisition code is inserted into the program of FIG.

図5に示すように、挿入部23は、strcpy(a,b)の直前の行に、取得コードとしてtrace()文を挿入し、変数aのサイズと、変数bの値の長さをログに出力させる。   As shown in FIG. 5, the insertion unit 23 inserts a trace () statement as an acquisition code in the line immediately before strcpy (a, b), and logs the size of the variable a and the length of the value of the variable b. To output.

このように本実施形態では、静的解析の結果に基づいて動的解析に用いる取得コードを自動的に挿入しているので、容易に動的解析を行うことができる。   Thus, in this embodiment, since the acquisition code used for the dynamic analysis is automatically inserted based on the result of the static analysis, the dynamic analysis can be easily performed.

図6は、図2における動的解析のステップS5の説明図である。   FIG. 6 is an explanatory diagram of step S5 of the dynamic analysis in FIG.

動的解析部25は、ビルド部26によってビルドされた実行モジュールを実行し(S31)、S3で挿入した取得コードによって、変数の値を出力した実行ログを生成する(S32)。   The dynamic analysis unit 25 executes the execution module built by the build unit 26 (S31), and generates an execution log that outputs the value of the variable using the acquisition code inserted in S3 (S32).

実効モジュールを実行すると、データ処理部11は、変数a,bのサイズを設定し(ソースコードの1,2行目に相当)、input.txtを読み取り専用で開き(ソースコードの3
行目に相当)、input.txtの文字を変数bに格納する。更に、データ処理部11は、変数
aのサイズと変数bの値の長さを実行ログに出力し(ソースコードの7行目に相当)、変数bの値を変数aに複写する(ソースコードの8行目に相当)。そして、データ処理部11は、input.txtの終端に達するまでソースコードの5〜10行目に相当する処理を繰り
返す。
When the effective module is executed, the data processing unit 11 sets the sizes of the variables a and b (corresponding to the first and second lines of the source code), and opens input.txt read-only (3 of the source code).
The character of input.txt is stored in the variable b. Further, the data processing unit 11 outputs the size of the variable a and the length of the value of the variable b to the execution log (corresponding to the seventh line of the source code), and copies the value of the variable b to the variable a (source code) Equivalent to line 8). Then, the data processing unit 11 repeats the processing corresponding to the 5th to 10th lines of the source code until the end of input.txt is reached.

図7は、上記実行モジュールの実行によって作成された実行ログの例を示す図である。図7の例1は、input.txtの文字が、1,3,2のケースであり、例2は、input.txtの文字が、1,3,10のケースである。   FIG. 7 is a diagram showing an example of an execution log created by executing the execution module. Example 1 in FIG. 7 is a case where the characters of input.txt are 1, 3 and 2, and Example 2 is a case where the characters of input.txt are 1, 3 and 10.

そして、動的解析部25は、取得コードによって取得した変数の値が動的解析条件を満たしているか否かによってバグか否かを判定する(S33)。そして、取得した変数の値が動的解析条件を満たしていない場合(S33,No)、例えば変数bの値の長さが変数aのサイズを超えていれば、バグである旨の解析結果をメモリに登録する(S34)。一方、取得した変数の値が動的解析条件を満たしている場合(S33,Yes)、例えば変数bの値の長さが変数aのサイズを超えていなければ、バグでない旨の解析結果をメモリに登録する(S35)。   Then, the dynamic analysis unit 25 determines whether or not there is a bug depending on whether or not the value of the variable acquired by the acquisition code satisfies the dynamic analysis condition (S33). And when the value of the acquired variable does not satisfy the dynamic analysis condition (S33, No), for example, if the length of the value of the variable b exceeds the size of the variable a, the analysis result indicating that it is a bug is displayed. Register in the memory (S34). On the other hand, if the acquired variable value satisfies the dynamic analysis condition (S33, Yes), for example, if the length of the variable b does not exceed the size of the variable a, the analysis result indicating that there is no bug is stored in the memory. (S35).

図8は、図2の解析結果の出力ステップS6の説明図である。   FIG. 8 is an explanatory diagram of the analysis result output step S6 of FIG.

動的解析S5の後、出力処理部25は、静的解析S2の解析結果と動的解析S5の解析
結果をメモリから取得し(S41)、S5の解析結果に基づきバグがあるか否かを判定する(S42)。バグがある場合(S42,Yes)、バグがある旨の結果証明書を生成して出力部15の表示装置に表示させる(S43)。
After the dynamic analysis S5, the output processing unit 25 acquires the analysis result of the static analysis S2 and the analysis result of the dynamic analysis S5 from the memory (S41), and determines whether there is a bug based on the analysis result of S5. Determine (S42). If there is a bug (S42, Yes), a result certificate indicating that there is a bug is generated and displayed on the display device of the output unit 15 (S43).

図9は、バグがある旨の結果証明書の例を示す図である。   FIG. 9 is a diagram illustrating an example of a result certificate indicating that there is a bug.

図9において、結果証明書の表示欄30は、静的解析の結果として行番号31、指摘ID32及びメッセージ33を表示し、動的解析の結果としてバグの有無(バグ判定)34を表示している。   In FIG. 9, the result certificate display field 30 displays a line number 31, an indication ID 32, and a message 33 as a result of the static analysis, and a bug presence / absence (bug determination) 34 as a result of the dynamic analysis. Yes.

図9では、ソースコードの7行目に指摘ID"pgr0532"のバグの可能性があり、テスト
ケースの動的解析でバグがあったことを示している。なお、図9において、表示欄30は、ソースコードの7行目について示しているが、複数行の結果を一覧表示しても良い。
FIG. 9 shows that there is a possibility of a bug with the indication ID “pgr0532” on the seventh line of the source code, and that there was a bug in the dynamic analysis of the test case. In FIG. 9, the display column 30 shows the seventh line of the source code, but a result of a plurality of lines may be displayed as a list.

また、オペレータがバグ判定34のBugをクリックすると、出力処理部25は、リンクした表示欄40を表示させる。   When the operator clicks Bug of the bug determination 34, the output processing unit 25 displays the linked display column 40.

結果証明書の表示欄40は、指摘ID42の他、動的解析のテストケース番号41、trace結果内容43、バグの個別判定44をテストケース毎に表示している。   In the result certificate display field 40, in addition to the indication ID 42, a test case number 41 of dynamic analysis, a trace result content 43, and an individual determination 44 of bugs are displayed for each test case.

図9では、テストケース1で複写元の値の長さを1、テストケース2で複写元の値の長さを3、テストケース3で複写元の値の長さを10としている。テストケース1,2では、複写元の値の長さが複写先を超えず、個別判定44がOKであるが、テストケース3では、複写元の値の長さが複写先を超えて、個別判定44がNGとなったことが分かる。   In FIG. 9, the length of the copy source value is 1 in test case 1, the length of the copy source value is 3 in test case 2, and the length of the copy source value is 10 in test case 3. In test cases 1 and 2, the length of the copy source value does not exceed the copy destination and the individual determination 44 is OK. However, in test case 3, the length of the copy source value exceeds the copy destination and is individually It can be seen that the decision 44 is NG.

一方、S42しでバグがないと判定した場合(S42,No)、出力処理部25は、バグがない旨の結果証明書を生成して出力部15の表示装置に表示させる(S44)。   On the other hand, if it is determined in S42 that there is no bug (S42, No), the output processing unit 25 generates a result certificate indicating that there is no bug and displays it on the display device of the output unit 15 (S44).

図10は、バグがない旨の結果証明書の例を示す図である。   FIG. 10 is a diagram illustrating an example of a result certificate indicating that there is no bug.

図10では、ソースコードの7行目に指摘ID"pgr0532"のバグの可能性があり、テス
トケースの動的解析でバグがなかったことを示している。なお、図10において、オペレータがバグ判定34のNot Bugをクリックすると、出力処理部25は、リンクした
表示欄40を表示させる。
FIG. 10 shows that there is a possibility of a bug with the indication ID “pgr0532” on the seventh line of the source code, and there was no bug in the dynamic analysis of the test case. In FIG. 10, when the operator clicks Not Bug of the bug determination 34, the output processing unit 25 displays the linked display column 40.

結果証明書の表示欄40は、指摘ID42の他、動的解析のテストケース番号41、trace結果内容43、バグの個別判定44をテストケース毎に表示している。   In the result certificate display field 40, in addition to the indication ID 42, a test case number 41 of dynamic analysis, a trace result content 43, and an individual determination 44 of bugs are displayed for each test case.

図10では、テストケース1で複写元の値の長さを1、テストケース2で複写元の値の長さを3、テストケース3で複写元の値の長さを2としている。テストケース1−3では、何れも複写元の値の長さが複写先を超えず、個別判定44がOKであることが分かる。   In FIG. 10, the length of the copy source value is 1 in test case 1, the length of the copy source value is 3 in test case 2, and the length of the copy source value is 2 in test case 3. In test cases 1-3, it can be seen that the length of the copy source value does not exceed the copy destination, and the individual determination 44 is OK.

以上のように、本実施形態の解析装置1は、静的解析によってバグの可能性がある部分のコード(命令)を特定し、当該コードに含まれる変数の値を取得するtraceコード(取
得コード)を自動挿入してプログラムを実行する。そして、解析装置1は、取得した値が動的解析条件を満たすか否かによってバグの有無を判定する。これにより、本実施形態の解析装置1は、オペレータが予めtraceコードを設定しなくても動的解析を行うことがで
きる。
また、本実施形態の解析装置1は、静的解析し、解析対象のコードに含まれる変数の値によって誤りが生じるか否かによって、バグの可能性があるコードを特定して変数の値を
取得する。このため本実施形態の解析装置1は、全ての変数の値を取得するよりも動的解析時間を短縮でき、また、バグの可能性のない値を含まない(ノイズの少ない)、適切な解析結果を得ることができる。
As described above, the analysis device 1 according to the present embodiment identifies a code (instruction) of a portion that may have a bug by static analysis, and acquires a value of a variable included in the code (acquisition code). ) Is automatically inserted and the program is executed. Then, the analysis apparatus 1 determines whether or not there is a bug depending on whether or not the acquired value satisfies the dynamic analysis condition. Thereby, the analysis apparatus 1 of this embodiment can perform a dynamic analysis even if an operator does not set a trace code beforehand.
In addition, the analysis apparatus 1 of the present embodiment performs static analysis, identifies a code that may be a bug and determines the value of the variable depending on whether or not an error occurs depending on the value of the variable included in the code to be analyzed. get. For this reason, the analysis apparatus 1 according to the present embodiment can shorten the dynamic analysis time as compared with acquiring all the values of variables, and does not include values that are not likely to be bugs (less noise), and appropriate analysis. The result can be obtained.

1. long data = 65535;
2. data = ????;
3. short x = data ;
本実施例1のプログラムについて、静的解析部22は、静的解析を行った場合、3行目のshort x = dataにおいて、左辺のshort int型の変数 "x" より右辺のlong int型の初期値 "data" のサイズが大きいため、バグの可能性があると判定する。
1.long data = 65535;
2.data = ????;
3. short x = data;
In the program of the first embodiment, when the static analysis unit 22 performs the static analysis, the short int type variable “x” on the left side in the short x = data on the third line has the long int type on the right side. Since the initial value "data" is large, it is determined that there is a possibility of a bug.

3行目のshort x = dataのように、変数に値を代入する命令であって、左辺のサイズよりも右辺のサイズが大きい場合、静的解析部22は、記憶部13のメッセージDBから対応する指摘メッセージpgr0383のフォームを抽出する。そして静的解析部22は、フォー
ム「pgr0383 @1 型の初期値 @2 は、 @3 型の @4 よりサイズが大きいため、正しい初期
値とならない可能性があります。」の置換用文字@1〜@4を取得したコードの値で置き換える。即ち、静的解析部22は、「long int型の初期値 "data" は、short int型の "x" よりサイズが大きいため、正しい初期値とならない可能性があります。」のように指摘メッセージを生成する。
In the case of an instruction for assigning a value to a variable, such as short x = data on the third line, and the size of the right side is larger than the size of the left side, the static analysis unit 22 responds from the message DB of the storage unit 13. Extract the form of the indication message pgr0383. The static analysis unit 22 then replaces the initial character @ 1 of the form "pgr0383 @ 1 type initial value @ 2 may not be the correct initial value because it is larger than @ 3 type @ 4." Replace ~ 4 with the value of the acquired code. That is, the static analysis unit 22 indicates that the initial value “data” of the long int type is not larger than the “x” of the short int type, and may not be a correct initial value. Is generated.

本実施例1の場合、2行目で代入されるdataの実際の値がshortの範囲ならば問題ない
が、dataの実際の値がshortの範囲を超えるとバグとなる。
In the case of the first embodiment, there is no problem if the actual value of data substituted in the second line is in the short range, but a bug occurs if the actual value of data exceeds the short range.

このため、静的解析部22によってバグの可能性を検出した場合、挿入部23は、抽出した指摘メッセージと対応する取得コードを記憶部13の挿入内容DBから索出する。   For this reason, when the possibility of a bug is detected by the static analysis unit 22, the insertion unit 23 retrieves the acquired code corresponding to the extracted indication message from the insertion content DB of the storage unit 13.

図11は、指摘ID(pgr0383)と対応する取得コード及び動的解析条件を示す図である
FIG. 11 is a diagram showing an acquisition code and dynamic analysis conditions corresponding to the indication ID (pgr0383).

そして、挿入部23は、索出した取得コードを次のようにソースコードに挿入する。   Then, the insertion unit 23 inserts the retrieved acquisition code into the source code as follows.

[挿入後のソースコード例]
1. long data = 65535;
2. data = ????;
3. trace("pgr0383, data = %d\n" data);
4. short x = data ;
動的解析部24は、取得コードを挿入したプログラムを実行してdataの値を取得し、動的解析条件に基づき、dataの値がshort xのサイズを超えていればバグと判定し、dataの
値がshort xのサイズを超えていなければバグでないと判定する。
[Example of source code after insertion]
1.long data = 65535;
2.data = ????;
3. trace ("pgr0383, data =% d \ n"data);
4. short x = data;
The dynamic analysis unit 24 executes the program in which the acquisition code is inserted to acquire the value of data. Based on the dynamic analysis condition, the dynamic analysis unit 24 determines that there is a bug if the data value exceeds the short x size. If the value of does not exceed the size of short x, it is determined not to be a bug.

20. fp = fopen( filename, "r" ) ;
21. size = fread( buf, sizeof(buf), 1, fp ) ; //pgr0520を指摘
本実施例2のプログラムについて、静的解析部22は、静的解析条件を満たしているか否かを判定した場合、21行目のsize = fread( buf, sizeof(buf), 1, fp )において、
変数fpが0番地を参照することがあるため、バグの可能性があると判定する。
20. fp = fopen (filename, "r");
21. size = fread (buf, sizeof (buf), 1, fp); // points out pgr0520 For the program of the second embodiment, the static analysis unit 22 determines whether or not the static analysis condition is satisfied. When size = fread (buf, sizeof (buf), 1, fp) on the 21st line,
Since the variable fp may refer to address 0, it is determined that there is a possibility of a bug.

21行目のsize = fread( buf, sizeof(buf), 1, fp )のように、0番地を参照する可
能性がある場合、静的解析部22は、記憶部13のメッセージDBから対応する指摘メッ
セージpgr0520のフォームを抽出する。そして静的解析部22は、フォーム「pgr0520 @1
行目で0番地を代入する可能性のある変数 @2 は0番地を参照している可能性があります。」の置換用文字@1〜@2を取得したコードの値で置き換える。即ち、静的解析部22は、「20行目で0番地を代入する可能性のある変数"fp"は0番地を参照している可能性があります。」のように指摘メッセージを生成する。
If there is a possibility of referring to address 0, as in size = fread (buf, sizeof (buf), 1, fp) on the 21st line, the static analysis unit 22 responds from the message DB of the storage unit 13. Extract the form of the indication message pgr0520. And the static analysis part 22 forms "pgr0520 @ 1
The variable @ 2 that may be assigned address 0 on the line may refer to address 0. The replacement characters @ 1 to @ 2 are replaced with the acquired code value. That is, the static analysis unit 22 generates an indication message such as “There is a possibility that the variable“ fp ”that may be assigned 0 address in the 20th line may refer to 0 address”.

本実施例2の場合、20行目でfopenが正常に実行されれば問題ないが、失敗した場合
、fpがNULLの状態で、21行目が実行されバグとなる。
In the case of the second embodiment, there is no problem if fopen is normally executed in the 20th line, but if it fails, the 21st line is executed with fp being NULL, resulting in a bug.

このため、静的解析部22によってバグの可能性を検出した場合、挿入部23は、抽出した指摘メッセージと対応する取得コードを記憶部13の挿入内容DBから索出する。   For this reason, when the possibility of a bug is detected by the static analysis unit 22, the insertion unit 23 retrieves the acquired code corresponding to the extracted indication message from the insertion content DB of the storage unit 13.

図12は、指摘ID(pgr0520)と対応する取得コード及び動的解析条件を示す図である
FIG. 12 is a diagram showing an acquisition code and dynamic analysis conditions corresponding to the indication ID (pgr0520).

そして、挿入部23は、索出した取得コードを次のようにソースコードに挿入する。   Then, the insertion unit 23 inserts the retrieved acquisition code into the source code as follows.

[挿入後のソースコード例]
20. fp = fopen( filename, "r" ) ;
21. trace("pgr0520, fp = %d\n" fp);
22. size = fread( buf, sizeof(buf), 1, fp ) ; //pgr0520を指摘
動的解析部24は、取得コードを挿入したプログラムを実行してfpの値を取得し、動的解析条件に基づき、fpの値がNullであればバグと判定し、fpの値がNullでなければバグでないと判定する。
[Example of source code after insertion]
20. fp = fopen (filename, "r");
21. trace ("pgr0520, fp =% d \ n"fp);
22. size = fread (buf, sizeof (buf), 1, fp); // Indicates pgr0520 The dynamic analysis unit 24 executes the program with the acquired code inserted to acquire the value of fp and performs dynamic analysis Based on the conditions, if the value of fp is Null, it is determined as a bug, and if the value of fp is not Null, it is determined that there is no bug.

1. int x = 0;
2. if( data != 1 )
3. [
4. x = 2;
5. ]
6. return data/x; //pgr0074
本実施例3のプログラムについて解析を開始し、静的解析部22が、静的解析条件を満たしているか否かを判定した場合、6行目のreturn data/xにおいて、0の可能性がある
変数xで除算しているため、バグの可能性があると判定する。
1.int x = 0;
2. if (data! = 1)
3. [
4. x = 2;
Five. ]
6. return data / x; // pgr0074
When the analysis of the program of the third embodiment is started and the static analysis unit 22 determines whether or not the static analysis condition is satisfied, there is a possibility of 0 in the return data / x on the sixth line. Since it is divided by the variable x, it is determined that there is a possibility of a bug.

6行目のreturn data/xのように、0の可能性がある変数xで除算している場合、静的
解析部22は、記憶部13のメッセージDBから対応する指摘メッセージpgr0074のフォ
ームを抽出する。そして静的解析部22は、フォーム「pgr0074 ゼロの可能性のある変数
@1 で除算しています。」の置換用文字@1を取得したコードの値で置き換える。即ち、静的解析部22は、「ゼロの可能性のある変数"x"で除算しています」のように指摘メッ
セージを生成する。
When dividing by a variable x that may be 0, such as return data / x on the sixth line, the static analysis unit 22 extracts the form of the corresponding indication message pgr0074 from the message DB of the storage unit 13 To do. Then, the static analysis unit 22 uses the variable “pgr0074 zero-possible variable”.
Dividing by @ 1. The replacement character @ 1 is replaced with the acquired code value. That is, the static analysis unit 22 generates an indication message such as “dividing by a variable“ x ”having a possibility of zero”.

本実施例3の場合、2行目のif文が真ならば、4行目でxに値が代入されるため問題な
いが、if文が偽であると、xが0のまま、6行目で除算が実行され、バグとなる。
In the case of the third embodiment, if the if statement in the second line is true, there is no problem because the value is assigned to x in the fourth line, but if the if statement is false, x remains 0 and 6 lines Divide by eye and bug.

このため、静的解析部22によってバグの可能性を検出した場合、挿入部23は、抽出した指摘メッセージと対応する取得コードを記憶部13の挿入内容DBから索出する。   For this reason, when the possibility of a bug is detected by the static analysis unit 22, the insertion unit 23 retrieves the acquired code corresponding to the extracted indication message from the insertion content DB of the storage unit 13.

図12は、指摘ID(pgr0074)と対応する取得コード及び動的解析条件を示す図である
FIG. 12 is a diagram illustrating an acquisition code and dynamic analysis conditions corresponding to the indication ID (pgr0074).

そして、挿入部23は、索出した取得コードを次のようにソースコードに挿入する。
1. int x = 0;
2. if( data != 1 )
3. [
4. x = 2;
5. ]
6. trace("pgr0074, x = %d\n" x);
7. return data/x; //pgr0074
動的解析部24は、取得コードを挿入したプログラムを実行してxの値を取得し、動的解析条件に基づき、xの値が0であればバグと判定し、xの値が0でなければバグでないと判定する。
Then, the insertion unit 23 inserts the retrieved acquisition code into the source code as follows.
1.int x = 0;
2. if (data! = 1)
3. [
4. x = 2;
Five. ]
6. trace ("pgr0074, x =% d \ n"x);
7.return data / x; // pgr0074
The dynamic analysis unit 24 executes the program in which the acquisition code is inserted to acquire the value of x. Based on the dynamic analysis conditions, the dynamic analysis unit 24 determines that the bug is if the value of x is 0, and the value of x is 0. If it is not, it is determined that it is not a bug.

1. int data[10];
2.
3. for(int i=0; i<=10; i++)
4. [
5. ※iが動的に変化するコード
6.
7. data[i] = 0; //pgr0013を指摘
8. ]
本実施例4のプログラムについて解析を開始し、静的解析部22が、静的解析条件を満たしているか否かを判定した場合、7行目のdata[i] = 0において、iに10が入り、1
行目で宣言した範囲を超える可能性があるため、バグの可能性があると判定する。
1. int data [10];
2.
3. for (int i = 0; i <= 10; i ++)
Four. [
5. Code where i changes dynamically
6.
7. data [i] = 0; // point out pgr0013
8.]
When the analysis of the program of the fourth embodiment is started and the static analysis unit 22 determines whether or not the static analysis condition is satisfied, 10 is set to i in data [i] = 0 on the seventh line. Enter 1
Since it may exceed the range declared in the line, it is determined that there is a possibility of a bug.

7行目のdata[i]のように、宣言した範囲を超える可能性がある場合、静的解析部22
は、記憶部13のメッセージDBから対応する指摘メッセージpgr0013のフォームを抽出
する。そして静的解析部22は、フォーム「pgr0013 @1 行目の for文で @2 には @3 が
はいるので、 @4 で配列の範囲を超えます。(配列宣言: @5 の @6 行目)」の置換用文字
@1を取得したコードの値で置き換える。即ち、静的解析部22は、「3 行目の for文で
"i" には "10" がはいるので、 "data[i]" で範囲を超えます。(配列宣言: "file.c" の
1 行目)」のように指摘メッセージを生成する。
When there is a possibility of exceeding the declared range as in data [i] on the seventh line, the static analysis unit 22
Extracts the form of the corresponding indication message pgr0013 from the message DB of the storage unit 13. And the static analysis part 22 will exceed the range of the array with @ 4 because @ 3 is in @ 2 in the for statement on the form "pgr0013 @ 1 line. (The @ 6 line of the array declaration: @ 5 Replace the replacement character @ 1 ") with the value of the acquired code. That is, the static analysis unit 22 reads “For statement on the third line.
"i" has "10", so "data [i]" will exceed the range. (Array declaration: "file.c"
1st line) ”and generate an indication message.

本実施例4の場合、5行目でiが10未満に変化していれば問題ないが、5行目でiが10であると、data[10]=0となり宣言した範囲を超えるので、バグとなる。   In the case of the fourth embodiment, there is no problem if i changes to less than 10 in the fifth line, but if i is 10 in the fifth line, data [10] = 0 and exceeds the declared range. It becomes a bug.

このため、静的解析部22によってバグの可能性を検出した場合、挿入部23は、抽出した指摘メッセージと対応する取得コードを記憶部13の挿入内容DBから索出する。   For this reason, when the possibility of a bug is detected by the static analysis unit 22, the insertion unit 23 retrieves the acquired code corresponding to the extracted indication message from the insertion content DB of the storage unit 13.

図13は、指摘ID(pgr0013)と対応する取得コード及び動的解析条件を示す図である
FIG. 13 is a diagram illustrating an acquisition code and dynamic analysis conditions corresponding to the indication ID (pgr0013).

そして、挿入部23は、索出した取得コードを次のようにソースコードに挿入する。
1. int data[10];
2.
3. for(int i=0; i<=10; i++)
4. [
5. ※iが動的に変化するコード
6.
7. trace("pgr0013, 値=%d\n" i);
8. data[i] = 0; //pgr0013を指摘
9. ]
Then, the insertion unit 23 inserts the retrieved acquisition code into the source code as follows.
1. int data [10];
2.
3. for (int i = 0; i <= 10; i ++)
Four. [
5. Code where i changes dynamically
6.
7. trace ("pgr0013, value =% d \ n"i);
8. data [i] = 0; // point out pgr0013
9.]

動的解析部24は、取得コードを挿入したプログラムを実行してiの値を取得し、動的解析条件に基づき、iの値が10であればバグと判定し、iの値が10未満であればバグでないと判定する。   The dynamic analysis unit 24 executes the program in which the acquisition code is inserted to acquire the value of i. Based on the dynamic analysis conditions, the dynamic analysis unit 24 determines that the bug is when the value of i is 10, and the value of i is less than 10. If so, it is determined that it is not a bug.

なお、本実施例4おいて、静的解析部22は、1行目の変数data[10]を設定するコードと、3行目の変数iを設定するコードに基づいて、data[i] = 0で変数data[i]の範囲を超える可能性があると判断している。即ち、静的解析部22は、5行目で動的に変数iの値が変わるので、実際にバグであるか否かを決定するのではなく、可能性があると指摘する。但し、変数iが動的に変化するコードとdata[i] = 0の間に、静的に変数iの値を決めるコードがあれば、静的解析部22は、このコードを考慮しても良い。例えば、6行目に変数iが10であれば他の処理へジャンプする命令を含むコードがあれば、data[i] = 0の
範囲を超えることがなくなり、バグの可能性がないと判定しても良い。
In the fourth embodiment, the static analysis unit 22 sets data [i] = based on the code for setting the variable data [10] on the first line and the code for setting the variable i on the third line. It is determined that 0 may exceed the range of variable data [i]. That is, the static analysis unit 22 points out that the value of the variable i dynamically changes in the fifth line, so that there is a possibility instead of determining whether or not it is actually a bug. However, if there is a code that statically determines the value of the variable i between the code in which the variable i dynamically changes and data [i] = 0, the static analysis unit 22 may consider this code. good. For example, if the variable i is 10 on the 6th line, if there is a code that includes an instruction that jumps to another process, it is determined that there is no possibility of a bug because the range of data [i] = 0 is not exceeded. May be.

〈その他〉
本発明は、上述の図示例にのみ限定されるものではなく、本発明の要旨を逸脱しない範囲内において種々変更を加え得ることは勿論である。
<Others>
The present invention is not limited to the illustrated examples described above, and various modifications can be made without departing from the scope of the present invention.

また、前述のプログラムは、コンピュータが読み取り可能な記録媒体に記録されたものでも良い。   The above-described program may be recorded on a computer-readable recording medium.

ここで、コンピュータが読み取り可能な記録媒体とは、データやプログラム等の情報を電気的、磁気的、光学的、機械的、または化学的作用によって蓄積し、コンピュータから読み取ることができる記録媒体をいう。このような記録媒体の内コンピュータから取り外し可能なものとしては、例えばフレキシブルディスク、光磁気ディスク、CD-ROM、CD-R/W、DVD、DAT、8mmテープ、メモリカード等がある。   Here, the computer-readable recording medium refers to a recording medium that accumulates information such as data and programs by electrical, magnetic, optical, mechanical, or chemical action and can be read from the computer. . Examples of such a recording medium that can be removed from the computer include a flexible disk, a magneto-optical disk, a CD-ROM, a CD-R / W, a DVD, a DAT, an 8 mm tape, and a memory card.

また、コンピュータに固定された記録媒体としてハードディスクやROM(リードオンリーメモリ)等がある。   Further, there are a hard disk, a ROM (read only memory) and the like as a recording medium fixed to the computer.

1 解析装置
14 入力部
15 出力部
21 取得部
22 静的解析部
23 挿入部
24 動的解析部
25 出力制御部
26 ビルド部
DESCRIPTION OF SYMBOLS 1 Analysis apparatus 14 Input part 15 Output part 21 Acquisition part 22 Static analysis part 23 Insertion part 24 Dynamic analysis part 25 Output control part 26 Build part

Claims (6)

コンピュータプログラムのコードを取得する取得部と、
取得した前記コードのうち、変数を含む部分のコードを解析対象とし、当該解析対象のコードが所定の静的解析条件を満たすか否かによってバグの可能性を判定する静的解析部と、
前記バグの可能性があると判定された解析対象のコードに含まれる前記変数の値を取得する取得コードを前記プログラムに挿入する挿入部と、
前記プログラムを実行し、前記取得コードによって取得した値を前記変数に代入した場合に前記解析対象のコードが所定の動的解析条件を満たすか否かによってバグを判定する動的解析部と、
を備えた解析装置。
An acquisition unit for acquiring a code of a computer program;
Of the acquired code, a static analysis unit that determines the possibility of a bug depending on whether or not a code including a variable includes a variable and the analysis target code satisfies a predetermined static analysis condition;
An insertion unit that inserts into the program an acquisition code for acquiring the value of the variable included in the code to be analyzed that is determined to have the possibility of the bug;
A dynamic analysis unit that executes the program and determines a bug depending on whether or not the analysis target code satisfies a predetermined dynamic analysis condition when the value acquired by the acquisition code is substituted into the variable;
Analysis device with
前記静的解析条件が、解析対象のコードに含まれる変数の値によって誤りが生じるか否かである請求項1に記載の解析装置。   The analysis apparatus according to claim 1, wherein the static analysis condition is whether or not an error occurs depending on a value of a variable included in a code to be analyzed. コンピュータプログラムのコードを取得するステップと、
取得した前記コードのうち、変数を含む部分のコードを解析対象とし、当該解析対象のコードが所定の静的解析条件を満たすか否かによってバグの可能性を判定するステップと、
前記バグの可能性があると判定された解析対象のコードに含まれる前記変数の値を取得する取得コードを前記プログラムに挿入するステップと、
前記プログラムを実行し、前記取得コードによって取得した値を前記変数に代入した場合に前記解析対象のコードが所定の動的解析条件を満たすか否かによってバグを判定するステップと、
をコンピュータが実行する解析方法。
Obtaining the code of the computer program;
Of the obtained code, a code including a part including a variable is set as an analysis target, and a step of determining a possibility of a bug depending on whether the analysis target code satisfies a predetermined static analysis condition;
Inserting an acquisition code for acquiring a value of the variable included in the analysis target code determined to be a bug, into the program;
Executing the program and determining a bug depending on whether or not the analysis target code satisfies a predetermined dynamic analysis condition when the value acquired by the acquisition code is substituted into the variable;
Analysis method that the computer executes.
前記静的解析条件が、解析対象のコードに含まれる変数の値によって誤りが生じるか否かである請求項3に記載の解析方法。   The analysis method according to claim 3, wherein the static analysis condition is whether or not an error occurs depending on a value of a variable included in a code to be analyzed. コンピュータプログラムのコードを取得するステップと、
取得した前記コードのうち、変数を含む部分のコードを解析対象とし、当該解析対象のコードが所定の静的解析条件を満たすか否かによってバグの可能性を判定するステップと、
前記バグの可能性があると判定された解析対象のコードに含まれる前記変数の値を取得する取得コードを前記プログラムに挿入するステップと、
前記プログラムを実行し、前記取得コードによって取得した値を前記変数に代入した場合に前記解析対象のコードが所定の動的解析条件を満たすか否かによってバグを判定するステップと、
をコンピュータに実行させるための解析プログラム。
Obtaining the code of the computer program;
Of the obtained code, a code including a part including a variable is set as an analysis target, and a step of determining a possibility of a bug depending on whether the analysis target code satisfies a predetermined static analysis condition;
Inserting an acquisition code for acquiring a value of the variable included in the analysis target code determined to be a bug, into the program;
Executing the program and determining a bug depending on whether or not the analysis target code satisfies a predetermined dynamic analysis condition when the value acquired by the acquisition code is substituted into the variable;
An analysis program that causes a computer to execute.
前記静的解析条件が、解析対象のコードに含まれる変数の値によって誤りが生じるか否かである請求項5に記載の解析プログラム。   The analysis program according to claim 5, wherein the static analysis condition is whether or not an error occurs depending on a value of a variable included in a code to be analyzed.
JP2009290612A 2009-12-22 2009-12-22 Program analysis apparatus and analysis method Expired - Fee Related JP5343840B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2009290612A JP5343840B2 (en) 2009-12-22 2009-12-22 Program analysis apparatus and analysis method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2009290612A JP5343840B2 (en) 2009-12-22 2009-12-22 Program analysis apparatus and analysis method

Publications (2)

Publication Number Publication Date
JP2011133966A true JP2011133966A (en) 2011-07-07
JP5343840B2 JP5343840B2 (en) 2013-11-13

Family

ID=44346665

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2009290612A Expired - Fee Related JP5343840B2 (en) 2009-12-22 2009-12-22 Program analysis apparatus and analysis method

Country Status (1)

Country Link
JP (1) JP5343840B2 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2018123065A1 (en) * 2016-12-29 2018-07-05 三菱電機株式会社 Program analysis system, program analyzer, program analysis method, and analysis program

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH06236295A (en) * 1992-03-16 1994-08-23 Nippon Telegr & Teleph Corp <Ntt> Program transplant supporting system
JP2002278801A (en) * 2001-03-21 2002-09-27 Ricoh Co Ltd Software inspecting method
JP2009193335A (en) * 2008-02-14 2009-08-27 Nec Corp Automatic annotation insertion method of static verification tool

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH06236295A (en) * 1992-03-16 1994-08-23 Nippon Telegr & Teleph Corp <Ntt> Program transplant supporting system
JP2002278801A (en) * 2001-03-21 2002-09-27 Ricoh Co Ltd Software inspecting method
JP2009193335A (en) * 2008-02-14 2009-08-27 Nec Corp Automatic annotation insertion method of static verification tool

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
CSND200800102007; 西田 啓一: '各種ツールの活かし方、効果的な使い方 回帰テストの上手な自動化 第6章 C++test ツールを用いた' ソフトウェア・テストPRESS Vol.6, 20080201, pp.132-135, (株)技術評論社 *
JPN6013034199; 西田 啓一: '各種ツールの活かし方、効果的な使い方 回帰テストの上手な自動化 第6章 C++test ツールを用いた' ソフトウェア・テストPRESS Vol.6, 20080201, pp.132-135, (株)技術評論社 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2018123065A1 (en) * 2016-12-29 2018-07-05 三菱電機株式会社 Program analysis system, program analyzer, program analysis method, and analysis program
JPWO2018123065A1 (en) * 2016-12-29 2019-04-04 三菱電機株式会社 Program analysis apparatus, program analysis system, program analysis method, and analysis program
US11068381B2 (en) 2016-12-29 2021-07-20 Mitsubishi Electric Corporation Program analysis device, program analysis system, program analysis method and computer readable medium

Also Published As

Publication number Publication date
JP5343840B2 (en) 2013-11-13

Similar Documents

Publication Publication Date Title
JP4148527B2 (en) Functional test script generator
US8539475B2 (en) API backward compatibility checking
US6430741B1 (en) System and method for data coverage analysis of a computer program
CN104899147B (en) A kind of code Static Analysis Method towards safety inspection
JP2006185211A (en) Program analysis system, test execution device, and analysis method and program thereof
JPWO2006087780A1 (en) Vulnerability audit program, vulnerability audit device, vulnerability audit method
TWI617983B (en) Method for performing cared-zone code coverage evaluation with no source code modification
US20120185669A1 (en) Program inspection method and non-transitory, computer readable storage medium storing inspection program
Michelon et al. The life cycle of features in highly-configurable software systems evolving in space and time
CN111919214A (en) Automatic generation of patches for security violations
JP6440895B2 (en) Software analysis apparatus and software analysis method
US7624304B2 (en) Defect detection for integers
US9189372B2 (en) Trace coverage analysis
JP5077455B2 (en) Vulnerability audit program, vulnerability audit device, vulnerability audit method
KR101583932B1 (en) Signature generation apparatus for generating signature of program and the method, malicious code detection apparatus for detecting malicious code of signature and the method
JP5343840B2 (en) Program analysis apparatus and analysis method
JP2009129204A (en) Code inspection system, code inspection method, and program
Mahmud et al. Acid: an api compatibility issue detector for android apps
KR101583133B1 (en) Method for evaluating software similarity using stack and apparatus therefor
JP4983027B2 (en) Check program and check method
JP6748357B2 (en) Analysis device, analysis program, and analysis method
JPH10293683A (en) Device for comparatively analyzing program, method therefor and mechanically readable recording medium recording comparative analytic program for program
KR102421394B1 (en) Apparatus and method for detecting malicious code using tracing based on hardware and software
JP5962779B2 (en) Flag access defect inspection device, flag access defect inspection method, flag access defect inspection program
JP2018147114A (en) Test case generation method, computer, and program

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20120910

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20130411

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20130416

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20130617

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: 20130716

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20130729

R150 Certificate of patent or registration of utility model

Ref document number: 5343840

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

Free format text: JAPANESE INTERMEDIATE CODE: R150

LAPS Cancellation because of no payment of annual fees