flaw_detector 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/.travis.yml +18 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +4 -0
- data/Rakefile +4 -0
- data/bin/flaw_detector +38 -0
- data/ext/insns_ext/extconf.rb +2 -0
- data/ext/insns_ext/insn_ext.rb +7 -0
- data/ext/insns_ext/insns.inc +179 -0
- data/ext/insns_ext/insns_ext.c +36 -0
- data/ext/insns_ext/insns_info.inc +695 -0
- data/flaw_detector.gemspec +26 -0
- data/lib/flaw_detector/code_model/cfg_node.rb +190 -0
- data/lib/flaw_detector/code_model/code_document.rb +63 -0
- data/lib/flaw_detector/code_model/insns_frame.rb +341 -0
- data/lib/flaw_detector/controller.rb +27 -0
- data/lib/flaw_detector/detector/abstract_detector.rb +10 -0
- data/lib/flaw_detector/detector/nil_false_path_flow.rb +179 -0
- data/lib/flaw_detector/formatter/csv_formatter.rb +24 -0
- data/lib/flaw_detector/message.rb +45 -0
- data/lib/flaw_detector/version.rb +3 -0
- data/lib/flaw_detector.rb +169 -0
- data/sample/flaw_in_code.rb +9 -0
- data/spec/lib/flaw_detector_spec.rb +526 -0
- data/spec/spec_helper.rb +7 -0
- metadata +92 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
before_install:
|
2
|
+
- ruby -C ext/insns_ext extconf.rb
|
3
|
+
- make -C ext/insns_ext
|
4
|
+
script:
|
5
|
+
- bundle
|
6
|
+
- rake spec
|
7
|
+
- rake install
|
8
|
+
rvm:
|
9
|
+
- 1.9.2
|
10
|
+
- 1.9.3
|
11
|
+
- 2.0.0
|
12
|
+
matrix:
|
13
|
+
allow_failures:
|
14
|
+
- rvm: 2.0.0
|
15
|
+
notifications:
|
16
|
+
email:
|
17
|
+
on_success: always
|
18
|
+
on_failure: always
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Rikiya Ayukawa
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer in the documentation and/or
|
11
|
+
other materials provided with the distribution.
|
12
|
+
* Neither the name of the DUO Interactive, LLC nor the names of its contributors
|
13
|
+
may be used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
17
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/flaw_detector
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
begin
|
5
|
+
require 'flaw_detector'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'flaw_detector'
|
9
|
+
end
|
10
|
+
|
11
|
+
def usage
|
12
|
+
puts " "*2 + "Usage:"
|
13
|
+
puts " "*4 + "#{File.basename($0)} [-f outfille] [--help] rbfile ..."
|
14
|
+
end
|
15
|
+
|
16
|
+
rl_opts = {:format => "csv"}
|
17
|
+
opt = OptionParser.new
|
18
|
+
opt.on('-f outfile') {|v| rl_opts[:outfile] = v }
|
19
|
+
opt.on('-h', '--help') {|v| usage;exit 0}
|
20
|
+
#opt.on('-t format', '--type format') {|v| rl_opts[:format] = v }
|
21
|
+
opt.parse!(ARGV)
|
22
|
+
|
23
|
+
if ARGV.size == 0
|
24
|
+
usage
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
io = STDOUT
|
29
|
+
io = File.open(rl_opts[:outfile], "w") if rl_opts[:outfile]
|
30
|
+
formatter = eval("FlawDetector::Formatter::#{rl_opts[:format].capitalize}Formatter").new(io)
|
31
|
+
con = FlawDetector::BasicController.new(formatter)
|
32
|
+
con.detectors << FlawDetector::Detector::NilFalsePathFlow.new
|
33
|
+
if con.run(ARGV)
|
34
|
+
puts "OK"
|
35
|
+
exit 0
|
36
|
+
else
|
37
|
+
exit 2 #found flaws
|
38
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
/** -*-c-*-
|
2
|
+
This file contains YARV instructions list.
|
3
|
+
|
4
|
+
----
|
5
|
+
This file is auto generated by insns2vm.rb
|
6
|
+
DO NOT TOUCH!
|
7
|
+
|
8
|
+
If you want to fix something, you must edit 'template/insns.inc.tmpl'
|
9
|
+
or insns2vm.rb
|
10
|
+
*/
|
11
|
+
|
12
|
+
|
13
|
+
/* BIN : Basic Instruction Name */
|
14
|
+
#define BIN(n) YARVINSN_##n
|
15
|
+
|
16
|
+
enum ruby_vminsn_type {
|
17
|
+
BIN(nop) = 0,
|
18
|
+
|
19
|
+
BIN(getlocal) = 1,
|
20
|
+
|
21
|
+
BIN(setlocal) = 2,
|
22
|
+
|
23
|
+
BIN(getspecial) = 3,
|
24
|
+
|
25
|
+
BIN(setspecial) = 4,
|
26
|
+
|
27
|
+
BIN(getdynamic) = 5,
|
28
|
+
|
29
|
+
BIN(setdynamic) = 6,
|
30
|
+
|
31
|
+
BIN(getinstancevariable) = 7,
|
32
|
+
|
33
|
+
BIN(setinstancevariable) = 8,
|
34
|
+
|
35
|
+
BIN(getclassvariable) = 9,
|
36
|
+
|
37
|
+
BIN(setclassvariable) = 10,
|
38
|
+
|
39
|
+
BIN(getconstant) = 11,
|
40
|
+
|
41
|
+
BIN(setconstant) = 12,
|
42
|
+
|
43
|
+
BIN(getglobal) = 13,
|
44
|
+
|
45
|
+
BIN(setglobal) = 14,
|
46
|
+
|
47
|
+
BIN(putnil) = 15,
|
48
|
+
|
49
|
+
BIN(putself) = 16,
|
50
|
+
|
51
|
+
BIN(putobject) = 17,
|
52
|
+
|
53
|
+
BIN(putspecialobject) = 18,
|
54
|
+
|
55
|
+
BIN(putiseq) = 19,
|
56
|
+
|
57
|
+
BIN(putstring) = 20,
|
58
|
+
|
59
|
+
BIN(concatstrings) = 21,
|
60
|
+
|
61
|
+
BIN(tostring) = 22,
|
62
|
+
|
63
|
+
BIN(toregexp) = 23,
|
64
|
+
|
65
|
+
BIN(newarray) = 24,
|
66
|
+
|
67
|
+
BIN(duparray) = 25,
|
68
|
+
|
69
|
+
BIN(expandarray) = 26,
|
70
|
+
|
71
|
+
BIN(concatarray) = 27,
|
72
|
+
|
73
|
+
BIN(splatarray) = 28,
|
74
|
+
|
75
|
+
BIN(checkincludearray) = 29,
|
76
|
+
|
77
|
+
BIN(newhash) = 30,
|
78
|
+
|
79
|
+
BIN(newrange) = 31,
|
80
|
+
|
81
|
+
BIN(pop) = 32,
|
82
|
+
|
83
|
+
BIN(dup) = 33,
|
84
|
+
|
85
|
+
BIN(dupn) = 34,
|
86
|
+
|
87
|
+
BIN(swap) = 35,
|
88
|
+
|
89
|
+
BIN(reput) = 36,
|
90
|
+
|
91
|
+
BIN(topn) = 37,
|
92
|
+
|
93
|
+
BIN(setn) = 38,
|
94
|
+
|
95
|
+
BIN(adjuststack) = 39,
|
96
|
+
|
97
|
+
BIN(defined) = 40,
|
98
|
+
|
99
|
+
BIN(trace) = 41,
|
100
|
+
|
101
|
+
BIN(defineclass) = 42,
|
102
|
+
|
103
|
+
BIN(send) = 43,
|
104
|
+
|
105
|
+
BIN(invokesuper) = 44,
|
106
|
+
|
107
|
+
BIN(invokeblock) = 45,
|
108
|
+
|
109
|
+
BIN(leave) = 46,
|
110
|
+
|
111
|
+
BIN(finish) = 47,
|
112
|
+
|
113
|
+
BIN(throw) = 48,
|
114
|
+
|
115
|
+
BIN(jump) = 49,
|
116
|
+
|
117
|
+
BIN(branchif) = 50,
|
118
|
+
|
119
|
+
BIN(branchunless) = 51,
|
120
|
+
|
121
|
+
BIN(getinlinecache) = 52,
|
122
|
+
|
123
|
+
BIN(onceinlinecache) = 53,
|
124
|
+
|
125
|
+
BIN(setinlinecache) = 54,
|
126
|
+
|
127
|
+
BIN(opt_case_dispatch) = 55,
|
128
|
+
|
129
|
+
BIN(opt_checkenv) = 56,
|
130
|
+
|
131
|
+
BIN(opt_plus) = 57,
|
132
|
+
|
133
|
+
BIN(opt_minus) = 58,
|
134
|
+
|
135
|
+
BIN(opt_mult) = 59,
|
136
|
+
|
137
|
+
BIN(opt_div) = 60,
|
138
|
+
|
139
|
+
BIN(opt_mod) = 61,
|
140
|
+
|
141
|
+
BIN(opt_eq) = 62,
|
142
|
+
|
143
|
+
BIN(opt_neq) = 63,
|
144
|
+
|
145
|
+
BIN(opt_lt) = 64,
|
146
|
+
|
147
|
+
BIN(opt_le) = 65,
|
148
|
+
|
149
|
+
BIN(opt_gt) = 66,
|
150
|
+
|
151
|
+
BIN(opt_ge) = 67,
|
152
|
+
|
153
|
+
BIN(opt_ltlt) = 68,
|
154
|
+
|
155
|
+
BIN(opt_aref) = 69,
|
156
|
+
|
157
|
+
BIN(opt_aset) = 70,
|
158
|
+
|
159
|
+
BIN(opt_length) = 71,
|
160
|
+
|
161
|
+
BIN(opt_size) = 72,
|
162
|
+
|
163
|
+
BIN(opt_succ) = 73,
|
164
|
+
|
165
|
+
BIN(opt_not) = 74,
|
166
|
+
|
167
|
+
BIN(opt_regexpmatch1) = 75,
|
168
|
+
|
169
|
+
BIN(opt_regexpmatch2) = 76,
|
170
|
+
|
171
|
+
BIN(opt_call_c_function) = 77,
|
172
|
+
|
173
|
+
BIN(bitblt) = 78,
|
174
|
+
|
175
|
+
BIN(answer) = 79,
|
176
|
+
|
177
|
+
VM_INSTRUCTION_SIZE = 80
|
178
|
+
};
|
179
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#define USE_INSN_STACK_INCREASE
|
2
|
+
#define USE_INSN_RET_NUM
|
3
|
+
#include "ruby.h"
|
4
|
+
|
5
|
+
#define VM_CALL_ARGS_BLOCKARG_BIT (0x01 << 2) //copy from vm_core.h
|
6
|
+
#include "insns.inc"
|
7
|
+
#include "insns_info.inc"
|
8
|
+
|
9
|
+
VALUE wrap_insn_len(VALUE self, VALUE insn)
|
10
|
+
{
|
11
|
+
int len = insn_len(FIX2INT(insn));
|
12
|
+
return INT2FIX(len);
|
13
|
+
}
|
14
|
+
|
15
|
+
VALUE wrap_insn_stack_increase(VALUE self, VALUE insn, VALUE ope_ary)
|
16
|
+
{
|
17
|
+
int inc = insn_stack_increase(0, FIX2INT(insn), RARRAY_PTR(ope_ary));
|
18
|
+
return INT2FIX(inc);
|
19
|
+
}
|
20
|
+
|
21
|
+
VALUE wrap_insn_ret_num(VALUE self, VALUE insn)
|
22
|
+
{
|
23
|
+
int ret_num = insn_ret_num(FIX2INT(insn));
|
24
|
+
return INT2FIX(ret_num);
|
25
|
+
}
|
26
|
+
|
27
|
+
void Init_insns_ext()
|
28
|
+
{
|
29
|
+
VALUE module;
|
30
|
+
|
31
|
+
module = rb_define_module("InsnExt");
|
32
|
+
rb_define_module_function(module, "insn_len", wrap_insn_len, 1);
|
33
|
+
rb_define_module_function(module, "insn_stack_increase", wrap_insn_stack_increase, 2);
|
34
|
+
rb_define_module_function(module, "insn_ret_num", wrap_insn_ret_num, 1);
|
35
|
+
}
|
36
|
+
|