fuzzr 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fuzz/log.rb ADDED
@@ -0,0 +1,97 @@
1
+ #--------------------------------------------------------------------
2
+ # @file log.rb
3
+ # @author Martin Corino
4
+ #
5
+ # @brief Fuzz logging support
6
+ #
7
+ # @copyright Copyright (c) Remedy IT Expertise BV
8
+ #--------------------------------------------------------------------
9
+ require 'fuzz/console'
10
+
11
+ module Fuzz
12
+
13
+ #
14
+ # Default Reporting/Logging
15
+ #
16
+ class Reporter
17
+ def initialize(output = Fuzz::Console)
18
+ @output = output
19
+ klass = class << self; self; end
20
+ klass.__send__(:include, @output.colorizer_include)
21
+ end
22
+
23
+ attr_reader :output
24
+
25
+ def log_error(msg)
26
+ output.error_println 'Fuzz - ', red(bold 'ERROR'), ' : ', msg
27
+ end
28
+
29
+ def log_warning(msg)
30
+ output.error_println 'Fuzz - ', yellow(bold 'WARNING'), ' : ', msg
31
+ end
32
+
33
+ def log_info(msg)
34
+ output.println 'Fuzz - ', msg
35
+ end
36
+
37
+ def show_error(msg)
38
+ log_error(msg)
39
+ end
40
+
41
+ def show_warning(msg)
42
+ log_error(msg)
43
+ end
44
+
45
+ def show_msg(msg)
46
+ log(msg)
47
+ end
48
+ end
49
+
50
+ module LogMethods
51
+ def log_fatal(msg, rc=1)
52
+ Fuzz.reporter.log_error(msg)
53
+ exit rc
54
+ end
55
+
56
+ def log_error(msg)
57
+ Fuzz.reporter.log_error(msg)
58
+ end
59
+
60
+ def log_warning(msg)
61
+ Fuzz.reporter.log_warning(msg)
62
+ end
63
+
64
+ def log_info(msg)
65
+ Fuzz.reporter.log_info(msg)
66
+ end
67
+
68
+ def log(lvl, msg)
69
+ Fuzz.reporter.log_info(msg) if lvl <= verbosity
70
+ end
71
+
72
+ def show_error(msg)
73
+ Fuzz.reporter.show_error(msg)
74
+ end
75
+
76
+ def show_warning(msg)
77
+ Fuzz.reporter.show_warning(msg)
78
+ end
79
+
80
+ def show_msg(msg)
81
+ Fuzz.reporter.show_msg(msg)
82
+ end
83
+
84
+ def verbosity
85
+ Fuzz.verbosity
86
+ end
87
+
88
+ def verbose?
89
+ verbosity > 1
90
+ end
91
+
92
+ def silent?
93
+ verbosity < 1
94
+ end
95
+ end
96
+
97
+ end # Fuzz
@@ -0,0 +1,208 @@
1
+ #--------------------------------------------------------------------
2
+ # @file options.rb
3
+ # @author Martin Corino
4
+ #
5
+ # @brief Options module for fuzz
6
+ #
7
+ # @copyright Copyright (c) Remedy IT Expertise BV
8
+ #--------------------------------------------------------------------
9
+
10
+ require 'ostruct'
11
+ require 'yaml'
12
+ require 'fuzz/log'
13
+
14
+ module Fuzz
15
+
16
+ FUZZRC = '.fuzzrc'
17
+ FUZZRC_GLOBAL = File.expand_path(File.join(ENV['HOME'] || ENV['HOMEPATH'] || '~', FUZZRC))
18
+
19
+ OPTIONS = OpenStruct.new
20
+
21
+ class << OPTIONS
22
+
23
+ include Fuzz::LogMethods
24
+
25
+ def options
26
+ self
27
+ end
28
+
29
+ class Config < OpenStruct
30
+
31
+ include Fuzz::LogMethods
32
+
33
+ def initialize(hash=nil)
34
+ super
35
+ @table = _merge(_defaults, @table)
36
+ end
37
+
38
+ def options
39
+ Fuzz.options
40
+ end
41
+
42
+ def merge(from)
43
+ _merge(@table, from)
44
+ self
45
+ end
46
+
47
+ def load(rcpath)
48
+ log(3, "Loading #{FUZZRC} from #{rcpath}")
49
+ _cfg = YAML.load(IO.read(rcpath))
50
+ log(4, "Read from #{rcpath}: [#{_cfg}]")
51
+ # handle automatic env var expansion in fzzr_paths
52
+ _cfg[:fzzr_paths] = (_cfg[:fzzr_paths] || []).collect do |p|
53
+ log(5, "Examining fzzr_path [#{p}]")
54
+ # for paths coming from rc files environment vars are immediately expanded and
55
+ p.gsub!(/\$([^\s\/]+)/) { |m| ENV[$1] }
56
+ log(6, "Expanded fzzr_path [#{p}]")
57
+ # resulting relative paths converted to absolute paths
58
+ if File.directory?(p) # relative to working dir?
59
+ p = File.expand_path(p)
60
+ else # relative to rc location?
61
+ _fp = File.expand_path(File.join(File.dirname(rcpath), p))
62
+ log(4, "Ignoring invalid fuzzer search path #{p} configured in #{rcpath}") unless File.directory?(_fp)
63
+ p = _fp
64
+ end
65
+ log(4, "Adding fuzzer search path: #{p}")
66
+ p
67
+ end
68
+ merge(_cfg)
69
+ end
70
+
71
+ def save(rcpath)
72
+ File.open(rcpath, 'w') {|f| f << YAML.dump(@table) }
73
+ end
74
+
75
+ protected
76
+
77
+ def _defaults
78
+ {
79
+ :brix_paths => []
80
+ }
81
+ end
82
+
83
+ def _merge(to, from)
84
+ from.each_pair do |(k,v)|
85
+ k = k.to_sym
86
+ if to.has_key?(k)
87
+ case to[k]
88
+ when Array
89
+ to[k].concat v
90
+ when Hash
91
+ to[k].merge!(v)
92
+ when OpenStruct
93
+ _merge(to[k].__send__(:table), v)
94
+ else
95
+ to[k] = v
96
+ end
97
+ else
98
+ to[k] = v
99
+ end
100
+ end
101
+ to
102
+ end
103
+
104
+ end
105
+
106
+ protected
107
+
108
+ def _defaults
109
+ {
110
+ :verbose => (ENV['FUZZ_VERBOSE'] || 1).to_i,
111
+ :recurse => true,
112
+ :apply_fix => false,
113
+ :config => Config.new({
114
+ :follow_symlink => true,
115
+ :exts => [],
116
+ :filenames => [],
117
+ :excludes => [],
118
+ :add_files => false,
119
+ :fzzr_paths => [],
120
+ :fzzr_opts => {},
121
+ :fzzr_excludes => []
122
+ })
123
+ }
124
+ end
125
+
126
+ def _rc_paths
127
+ @rc_paths ||= []
128
+ end
129
+ def _loaded_rc_paths
130
+ @loaded_rc_paths ||= []
131
+ end
132
+
133
+ def _add_rcpath(path)
134
+ if _loaded_rc_paths.include?(File.expand_path(path))
135
+ log(3, "ignoring already loaded rc : #{path}")
136
+ else
137
+ log(3, "adding rc path : #{path}")
138
+ _rc_paths << path
139
+ end
140
+ _rc_paths
141
+ end
142
+
143
+ public
144
+
145
+ def reset
146
+ @table.clear
147
+ @table.merge!(_defaults)
148
+ _rc_paths.clear
149
+ _rc_paths << FUZZRC_GLOBAL
150
+ _loaded_rc_paths.clear
151
+ (ENV['FUZZRC'] || '').split(/:|;/).each do |p|
152
+ _add_rcpath(p)
153
+ end
154
+ end
155
+
156
+ def load_config
157
+ # first collect config from known (standard and configured) locations
158
+ _rc_paths.collect {|path| File.expand_path(path) }.each do |rcp|
159
+ log(3, "Testing rc path #{rcp}")
160
+ if File.readable?(rcp) && !_loaded_rc_paths.include?(rcp)
161
+ _cfg = Config.new.load(rcp)
162
+ self[:config].merge(_cfg)
163
+ _loaded_rc_paths << rcp
164
+ else
165
+ log(3, "Ignoring #{File.readable?(rcp) ? 'already loaded' : 'inaccessible'} rc path #{rcp}")
166
+ end
167
+ end
168
+ # now scan working path for any rc files unless specified otherwise
169
+ unless self[:no_rc_scan]
170
+ _cwd = File.expand_path(Dir.getwd)
171
+ log(3, "scanning working path #{_cwd} for rc files")
172
+ # first collect any rc files found
173
+ _rcpaths = []
174
+ begin
175
+ _rcp = File.join(_cwd, FUZZRC)
176
+ if File.readable?(_rcp) && !_loaded_rc_paths.include?(_rcp)
177
+ _rcpaths << _rcp
178
+ else
179
+ log(3, "Ignoring #{File.readable?(_rcp) ? 'already loaded' : 'inaccessible'} rc path #{_rcp}")
180
+ end
181
+ break if /\A(.:(\\|\/)|\.|\/)\Z/ =~ _cwd
182
+ _cwd = File.dirname(_cwd)
183
+ end while true
184
+ # now load them in reverse order
185
+ _rcpaths.reverse.each do |_rcp|
186
+ _cfg = Config.new.load(_rcp)
187
+ self[:config].merge(_cfg)
188
+ _loaded_rc_paths << _rcp
189
+ end
190
+ end
191
+ # lastly merge config specified by user on commandline
192
+ self[:config].merge(user_config)
193
+ end
194
+
195
+ def add_config(rcpath)
196
+ log_fatal("inaccessible rc path specified : #{rcpath}") unless File.readable?(rcpath)
197
+ _add_rcpath(rcpath)
198
+ end
199
+
200
+ def user_config
201
+ @user_config ||= Config.new
202
+ end
203
+
204
+ end # OPTIONS class
205
+
206
+ OPTIONS.reset # initialize
207
+
208
+ end # Fuzz
@@ -0,0 +1,85 @@
1
+ #--------------------------------------------------------------------
2
+ # @file screen.rb
3
+ # @author Martin Corino
4
+ #
5
+ # @brief Fuzz screen wrapper
6
+ #
7
+ # @copyright Copyright (c) Remedy IT Expertise BV
8
+ #--------------------------------------------------------------------
9
+ require 'fuzz/system'
10
+
11
+ module Fuzz
12
+
13
+ class Screen
14
+
15
+ class Color
16
+ def initialize(code)
17
+ @code = code
18
+ end
19
+ attr_reader :code
20
+ def to_s
21
+ ''
22
+ end
23
+ alias :to_str :to_s
24
+ end
25
+
26
+ COLORS = {
27
+ black: [Color.new("\e[30m"), Color.new("\e[m")],
28
+ red: [Color.new("\e[31m"), Color.new("\e[m")],
29
+ green: [Color.new("\e[32m"), Color.new("\e[m")],
30
+ yellow: [Color.new("\e[33m"), Color.new("\e[m")],
31
+ blue: [Color.new("\e[34m"), Color.new("\e[m")],
32
+ magenta: [Color.new("\e[34m"), Color.new("\e[m")],
33
+ bold: [Color.new("\e[1m"), Color.new("\e[m")],
34
+ reverse: [Color.new("\e[7m"), Color.new("\e[m")],
35
+ underline:[Color.new("\e[4m"), Color.new("\e[m")]
36
+ }
37
+
38
+ module ColorizeMethods
39
+ def self.included(mod)
40
+ Screen::COLORS.keys.each do |color|
41
+ mod.module_eval <<-EOT, __FILE__, __LINE__+1
42
+ def #{color}(s)
43
+ [Fuzz::Screen::COLORS[:#{color}].first, s, Fuzz::Screen::COLORS[:#{color}].last]
44
+ end
45
+ EOT
46
+ end
47
+ end
48
+ end
49
+
50
+ def initialize(output = STDOUT, input = STDIN, errout = STDERR)
51
+ @output = output
52
+ @input = input
53
+ @errout = errout
54
+ @colorize = output.tty? && Fuzz::Sys.has_ansi?
55
+ end
56
+
57
+ attr_reader :input, :output, :errout
58
+
59
+ def colorize?
60
+ @colorize
61
+ end
62
+
63
+ def output_cols
64
+ 80
65
+ end
66
+
67
+ def print(*args)
68
+ output.print args.flatten.collect {|a| (colorize? && Color === a) ? a.code : a }.join
69
+ end
70
+
71
+ def println(*args)
72
+ output.puts args.flatten.collect {|a| (colorize? && Color === a) ? a.code : a }.join
73
+ end
74
+
75
+ def error_print(*args)
76
+ errout.print args.flatten.collect {|a| (colorize? && Color === a) ? a.code : a }.join
77
+ end
78
+
79
+ def error_println(*args)
80
+ errout.puts args.flatten.collect {|a| (colorize? && Color === a) ? a.code : a }.join
81
+ end
82
+
83
+ end # Screen
84
+
85
+ end # Fuzz
@@ -0,0 +1,57 @@
1
+ #--------------------------------------------------------------------
2
+ # @file system.rb
3
+ # @author Martin Corino
4
+ #
5
+ # @brief System support for Fuzz
6
+ #
7
+ # @copyright Copyright (c) Remedy IT Expertise BV
8
+ #--------------------------------------------------------------------
9
+ require 'fileutils'
10
+
11
+ module Fuzz
12
+
13
+ module Sys
14
+
15
+ module SysMethods
16
+
17
+ def mswin?
18
+ /mingw/ =~ RUBY_PLATFORM ? true : false
19
+ end
20
+
21
+ def has_ansi?
22
+ # only ANSI escape code support on Windows
23
+ # if ANSICON (https://github.com/adoxa/ansicon) installed
24
+ (!mswin?) || ENV['ANSICON']
25
+ end
26
+
27
+ def in_dir(dir, &block)
28
+ STDERR.puts "cd #{dir}" if Fuzz.verbose?
29
+ rc = if Fuzz.dryrun?
30
+ yield if block_given?
31
+ else
32
+ Dir.chdir(dir, &block)
33
+ end
34
+ STDERR.puts "cd -" if Fuzz.verbose?
35
+ rc
36
+ end
37
+ def mv(src, tgt)
38
+ FileUtils.move(src, tgt, :verbose => Fuzz.verbose?)
39
+ end
40
+
41
+ def cp(src, tgt)
42
+ FileUtils.copy(src, tgt, :verbose => Fuzz.verbose?)
43
+ end
44
+
45
+ def chmod(mode, path)
46
+ FileUtils.chmod(mode, path, :verbose => Fuzz.verbose?)
47
+ end
48
+
49
+ end # SysMethods
50
+
51
+ class << self
52
+ include Sys::SysMethods
53
+ end
54
+
55
+ end # Sys
56
+
57
+ end # Fuzz
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ # -------------------------------------------------------------------
3
+ # version.rb - TAOX11 fuzz checker
4
+ #
5
+ # Author: Martin Corino
6
+ #
7
+ # Copyright (c) Remedy IT Expertise BV
8
+ # -------------------------------------------------------------------
9
+
10
+ module Fuzz
11
+
12
+ FUZZ_VERSION_MAJOR = 0
13
+ FUZZ_VERSION_MINOR = 9
14
+ FUZZ_VERSION_RELEASE = 11
15
+ FUZZ_VERSION = "#{FUZZ_VERSION_MAJOR}.#{FUZZ_VERSION_MINOR}.#{FUZZ_VERSION_RELEASE}"
16
+ FUZZ_COPYRIGHT = "Copyright (c) 2012-#{Time.now.year} Remedy IT Expertise BV, The Netherlands".freeze
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fuzzr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.11
5
+ platform: ruby
6
+ authors:
7
+ - Johnny Willemsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Fuzzer
14
+ email: jwillemsen@remedy.nl
15
+ executables:
16
+ - fuzz
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - LICENSE
20
+ - README.rdoc
21
+ files:
22
+ - LICENSE
23
+ - README.rdoc
24
+ - bin/fuzz
25
+ - fuzzers/check_ace_error.excludes
26
+ - fuzzers/check_ace_error.rb
27
+ - fuzzers/check_catch_ex_as_const.rb
28
+ - fuzzers/check_cout_cerr.excludes
29
+ - fuzzers/check_cout_cerr.rb
30
+ - fuzzers/check_executablebit.rb
31
+ - fuzzers/check_exit_keyword.excludes
32
+ - fuzzers/check_exit_keyword.rb
33
+ - fuzzers/check_fileheader.excludes
34
+ - fuzzers/check_fileheader.rb
35
+ - fuzzers/check_filename.excludes
36
+ - fuzzers/check_filename.rb
37
+ - fuzzers/check_id_tag.rb
38
+ - fuzzers/check_new_delete.excludes
39
+ - fuzzers/check_new_delete.rb
40
+ - fuzzers/check_printf_keyword.excludes
41
+ - fuzzers/check_printf_keyword.rb
42
+ - fuzzers/check_taox11_namespace.excludes
43
+ - fuzzers/check_taox11_namespace.rb
44
+ - lib/fuzz/console.rb
45
+ - lib/fuzz/fuzz.rb
46
+ - lib/fuzz/fuzzers/check_whitespace.rb
47
+ - lib/fuzz/fzzr.rb
48
+ - lib/fuzz/log.rb
49
+ - lib/fuzz/options.rb
50
+ - lib/fuzz/screen.rb
51
+ - lib/fuzz/system.rb
52
+ - lib/fuzz/version.rb
53
+ homepage: https://github.com/RemedyIT/fuzzr
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ bug_tracker_uri: https://github.com/RemedyIT/fuzzr/issues
58
+ source_code_uri: https://github.com/RemedyIT/fuzzr
59
+ post_install_message:
60
+ rdoc_options:
61
+ - "--main"
62
+ - README.rdoc
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '2.5'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.1.6
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: fuzzr
80
+ test_files: []