nasl-pedant 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pedant/checks/arity_of_builtins.rb +43 -10
- data/lib/pedant/commands/check.rb +2 -2
- data/lib/pedant/version.rb +1 -1
- data/test/unit/checks/test_arity_of_builtins.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d41b8fcbe0898ca2aab9a2fcc9e1a7ef90ca900d
|
4
|
+
data.tar.gz: 0deb90491e2b59d9ebbd38f005306ae1b5aac425
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daa101baef76f0482ce3fec9dc479a40f7b03393bca55a53703a66efbd51debf6e0f6927ed394010f664450965e1f268b1e448d28bf787b276739f5369363103
|
7
|
+
data.tar.gz: 3f650035854cb18e97d652dba398db8e5352efac1386ba3a84551548f691242d58c4972295c89c7c153de612b54044afd49b0e66654e6c6bba29634084dc72e1
|
@@ -30,22 +30,46 @@ module Pedant
|
|
30
30
|
class CheckArityOfBuiltins < Check
|
31
31
|
@@anon_arity_of_one = Set.new [
|
32
32
|
"isnull",
|
33
|
+
# Sockets
|
34
|
+
"get_port_state",
|
35
|
+
"get_tcp_port_state",
|
36
|
+
"get_udp_port_state",
|
37
|
+
"close",
|
38
|
+
# String functions
|
39
|
+
"strlen",
|
40
|
+
"int",
|
41
|
+
"uint",
|
42
|
+
"chomp",
|
43
|
+
"ord",
|
44
|
+
"hex",
|
45
|
+
"hexstr",
|
46
|
+
"tolower",
|
47
|
+
"toupper",
|
48
|
+
"xmlparse",
|
49
|
+
# Time
|
33
50
|
"usleep",
|
34
51
|
"sleep",
|
52
|
+
# Arrays and lists
|
35
53
|
"keys",
|
36
54
|
"max_index",
|
55
|
+
"sort",
|
56
|
+
# Runtime checks
|
37
57
|
"typeof",
|
58
|
+
"typeof_ex",
|
38
59
|
"defined_func",
|
60
|
+
# Bignum functions
|
39
61
|
"bn_dec2raw",
|
40
62
|
"bn_raw2dec",
|
41
63
|
"bn_hex2raw",
|
42
64
|
"bn_raw2hex",
|
43
65
|
"bn_sqr",
|
66
|
+
# File system
|
44
67
|
"fread",
|
45
68
|
"unlink",
|
46
69
|
"readdir",
|
47
70
|
"mkdir",
|
48
71
|
"rmdir",
|
72
|
+
# Unkeyed hashes (crypto)
|
49
73
|
"SHA",
|
50
74
|
"SHA1",
|
51
75
|
"SHA224",
|
@@ -56,6 +80,7 @@ module Pedant
|
|
56
80
|
"MD2",
|
57
81
|
"MD4",
|
58
82
|
"MD5",
|
83
|
+
# Knowledge base
|
59
84
|
"get_kb_item",
|
60
85
|
"get_kb_list",
|
61
86
|
"get_global_kb_item",
|
@@ -68,20 +93,28 @@ module Pedant
|
|
68
93
|
|
69
94
|
def check(file, tree)
|
70
95
|
tree.all(:Call).each do |call|
|
71
|
-
next unless @@anon_arity_of_one.include? call.name.ident.name
|
72
96
|
next unless call.name.indexes == []
|
73
|
-
|
97
|
+
name = call.name.ident.name
|
74
98
|
|
75
|
-
|
76
|
-
|
99
|
+
if @@anon_arity_of_one.include? name
|
100
|
+
next if call.args.length == 1 and call.args.first.type == :anonymous
|
101
|
+
fail
|
102
|
+
report(:error, "The builtin function '#{name}' takes a single anonymous argument.")
|
103
|
+
# Pick the right thing to highlight.
|
104
|
+
if call.args.length == 0
|
105
|
+
report(:error, call.context(call))
|
106
|
+
elsif call.args.first.type != :anonymous
|
107
|
+
report(:error, call.args[0].context(call))
|
108
|
+
elsif call.args.length > 1
|
109
|
+
report(:error, call.args[1].context(call))
|
110
|
+
end
|
111
|
+
end
|
77
112
|
|
78
|
-
|
79
|
-
|
113
|
+
if name == "make_array"
|
114
|
+
next if call.args.length.even?
|
115
|
+
fail
|
116
|
+
report(:error, "The builtin function 'make_array()' takes an even number of arguments.")
|
80
117
|
report(:error, call.context(call))
|
81
|
-
elsif call.args.first.type != :anonymous
|
82
|
-
report(:error, call.args[0].context(call))
|
83
|
-
elsif call.args.length > 1
|
84
|
-
report(:error, call.args[1].context(call))
|
85
118
|
end
|
86
119
|
end
|
87
120
|
end
|
@@ -109,7 +109,7 @@ module Pedant
|
|
109
109
|
|
110
110
|
def self.run_all(opts, args)
|
111
111
|
# Separate plugins and libraries from the rest of the arguments.
|
112
|
-
paths = args.select { |a| a =~ /(\/|\.(inc|nasl))$/ }
|
112
|
+
paths = args.select { |a| a =~ /(\/|\.(inc|nasl|pasl|tasl))$/ }
|
113
113
|
args -= paths
|
114
114
|
|
115
115
|
# If we have paths that aren't acceptable, there's a problem.
|
@@ -123,7 +123,7 @@ module Pedant
|
|
123
123
|
paths.each do |path|
|
124
124
|
begin
|
125
125
|
Pathname.new(path).find do |dirent|
|
126
|
-
if dirent.file? && dirent.extname =~ /inc|nasl/
|
126
|
+
if dirent.file? && dirent.extname =~ /inc|nasl|pasl|tasl/
|
127
127
|
dirents << dirent
|
128
128
|
end
|
129
129
|
end
|
data/lib/pedant/version.rb
CHANGED
@@ -82,4 +82,20 @@ class TestArityOfBuiltins < Test::Unit::TestCase
|
|
82
82
|
%q|get_kb_item("hello/", index:index);|
|
83
83
|
)
|
84
84
|
end
|
85
|
+
|
86
|
+
def test_make_array_odd
|
87
|
+
check(
|
88
|
+
:fail,
|
89
|
+
:CheckArityOfBuiltins,
|
90
|
+
%q|make_array(1, 2, 3);|
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_make_array_even
|
95
|
+
check(
|
96
|
+
:pass,
|
97
|
+
:CheckArityOfBuiltins,
|
98
|
+
%q|make_array(1, 2, 3, 4);|
|
99
|
+
)
|
100
|
+
end
|
85
101
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nasl-pedant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mak Kolybabi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-07-
|
13
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|