nasl-pedant 0.0.9 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTMwZjIxMTcwYzEzYTEyNGVmNWU5OTg1MmY2YWMyZjJmYjFiYjNhMg==
4
+ MzAxNGZlNTBhZWE1ODNkNTYyNjgxZmYxM2Y2NGNkYTgyMjhjMDY0ZQ==
5
5
  data.tar.gz: !binary |-
6
- MzNmOGUwY2E5NDFjZjgzZDg3ZGM1YzNhMDY4NjkzN2I0OGE1OWIxZA==
6
+ ODlhZTc4MGMxMjdlZGYzYzBiYWY4NDYzMzUzNGNmMGNlODU2ZDhlOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- M2M4MzkzMmJhYjJkZTYzM2VjODVmNjM4ODMzMjM0OGNiMTg3MWJlZWNkMDEx
10
- MDVjYThiMjRjZGQ2ZDJjM2YzMGUxMTMyNDNlMGEzZjRkZDQwZDU3Y2I5ZWQ2
11
- MTA5NzU2NjIxNDY5MGZhYWEzOWViOTRkYmZmNTQ1OTA3ZmVlODM=
9
+ N2E5MGRlNzE4MTk0ZWM1ODU2NTMwYWVlZTRlYjEwMDBjMDViM2ZjMjhiMTJh
10
+ YTQzYTRhODE1NTQwNzJhOWI2ZWY5MzUxZjJkNmZkMjQwNTZkOTc5ODMwZDE4
11
+ ZTYwMzUzOGE2ZTI5ODE3YTg1NmIzMjc1MGMzNzZkMjBlYTQzMzc=
12
12
  data.tar.gz: !binary |-
13
- MzMwN2Q3YjliZWE1YjIzNGUxNThkYThiMWI4Y2MyZDYyM2M5MGQ5ZTc1NTkx
14
- YzYwNmY5Y2M5OTQ5OTU4MTBkOGQ3ZmZkZDU3NTc4MTZjYmJlMTVlNGNmMGY0
15
- YzVmOTliMDQ3NTkyZWMzNDlmZGIyOGM3ZDVkNmY1NDkxOGRmZTI=
13
+ ZGE5MDdjNGNmMjk0ZjI2YWVkNzViY2U2MzU4MGQ4NTdkN2YyNjk0OWJmYzE0
14
+ N2ZjOWY0ZTVhZDgxOGRlYmFkNmJiN2Y4MDMwMjY1MjM3YmVlMDI1ZmUxOTE0
15
+ MzA5MjkzMTM3YjlmZDUzN2Q5MTNlOWE3N2FjMzI2NzFhOGZhYmY=
@@ -0,0 +1,99 @@
1
+ ################################################################################
2
+ # Copyright (c) 2015, Tenable Network Security
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ ################################################################################
26
+
27
+ require 'set'
28
+
29
+ module Pedant
30
+ class CheckArityOfBuiltins < Check
31
+ @@anon_arity_of_one = Set.new [
32
+ "isnull",
33
+ "usleep",
34
+ "sleep",
35
+ "keys",
36
+ "max_index",
37
+ "typeof",
38
+ "defined_func",
39
+ "bn_dec2raw",
40
+ "bn_raw2dec",
41
+ "bn_hex2raw",
42
+ "bn_raw2hex",
43
+ "bn_sqr",
44
+ "fread",
45
+ "unlink",
46
+ "readdir",
47
+ "mkdir",
48
+ "rmdir",
49
+ "SHA",
50
+ "SHA1",
51
+ "SHA224",
52
+ "SHA256",
53
+ "SHA384",
54
+ "SHA512",
55
+ "RIPEMD160",
56
+ "MD2",
57
+ "MD4",
58
+ "MD5",
59
+ "get_kb_item",
60
+ "get_kb_list",
61
+ "get_global_kb_item",
62
+ "get_global_kb_list",
63
+ ]
64
+
65
+ def self.requires
66
+ super + [:trees]
67
+ end
68
+
69
+ def check(file, tree)
70
+ tree.all(:Call).each do |call|
71
+ next unless @@anon_arity_of_one.include? call.name.ident.name
72
+ next unless call.name.indexes == []
73
+ next unless call.args.length != 1 or call.args.first.type != :anonymous
74
+
75
+ fail
76
+ report(:error, "The builtin function '#{call.name.ident.name}' takes a single anonymous argument.")
77
+
78
+ # Pick the right thing to highlight.
79
+ if call.args.length == 0
80
+ 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
+ else
86
+ raise "hello"
87
+ end
88
+ end
89
+ end
90
+
91
+ def run
92
+ # This check will pass by default.
93
+ pass
94
+
95
+ # Run this check on the tree from every file.
96
+ @kb[:trees].each { |file, tree| check(file, tree) }
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,92 @@
1
+ ################################################################################
2
+ # Copyright (c) 2015, Tenable Network Security
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ ################################################################################
26
+
27
+ require 'set'
28
+
29
+ module Pedant
30
+ class CheckNonsenseComparison < Check
31
+ def self.requires
32
+ super + [:trees]
33
+ end
34
+
35
+ def check(file, tree)
36
+ literals = Set.new [
37
+ Nasl::Array,
38
+ Nasl::List,
39
+ Nasl::Integer,
40
+ Nasl::String,
41
+ Nasl::Ip
42
+ ]
43
+
44
+ comparisons = Set.new [ "==", "!=", "=~", "!~", "><", ">!<", "<", ">", "<=", ">=" ]
45
+
46
+ # isnull() with a literal (never FALSE).
47
+ tree.all(:Call).each do |call|
48
+ next if call.name.ident.name != "isnull"
49
+ next if call.name.indexes != []
50
+ next if call.args.length != 1
51
+ next if not literals.include? call.args.first.expr.class
52
+ fail
53
+ report(:error, "isnull() is called with a literal, which can never be FALSE.")
54
+ report(:error, call.args.first.context(call))
55
+ end
56
+
57
+ # Comparing a literal to another literal (either TRUE or FALSE, but pointless).
58
+ tree.all(:Expression).each do |expr|
59
+ next if not literals.include? expr.lhs.class
60
+ next if not literals.include? expr.rhs.class
61
+ next if not comparisons.include? expr.op.to_s
62
+ fail
63
+ report(:error, "Comparing two literals is always TRUE or FALSE.")
64
+ report(:error, expr.op.context(expr))
65
+ end
66
+
67
+ # Comparing something against itself.
68
+ tree.all(:Expression).each do |expr|
69
+ next if not comparisons.include? expr.op.to_s
70
+ next if not expr.lhs.is_a? Nasl::Lvalue
71
+ next if not expr.rhs.is_a? Nasl::Lvalue
72
+ # Compare the XML representations of the two Lvalues.
73
+ # Handles integer keys nicely, so these two are the same: a[0x01] == a[1]
74
+ xmls = [:lhs, :rhs].map do |side|
75
+ expr.send(side).to_xml(Builder::XmlMarkup.new)
76
+ end
77
+ next if xmls[0] != xmls[1]
78
+ fail
79
+ report(:error, "Comparing two identical Lvalues. This will always be TRUE.")
80
+ report(:error, expr.op.context(expr))
81
+ end
82
+ end
83
+
84
+ def run
85
+ # This check will pass by default.
86
+ pass
87
+
88
+ # Run this check on the tree from every file.
89
+ @kb[:trees].each { |file, tree| check(file, tree) }
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,61 @@
1
+ ################################################################################
2
+ # Copyright (c) 2015, Tenable Network Security
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ ################################################################################
26
+
27
+ module Pedant
28
+ class CheckUsesOctalIntegers < Check
29
+ def self.requires
30
+ super + [:trees]
31
+ end
32
+
33
+ def check(file, tree)
34
+ tree.all(:Integer).select { |i| i.tokens.first.type == :INT_OCT }.each do |i|
35
+ next if i.value == 0 # Lots of plugins use '00' or '0000', which is ok.
36
+ warn
37
+ report(:warn, "NASL integers beginning with '0' with all digits between 0-7 are octal.")
38
+ report(:warn, "This integer will have decimal value '#{i.value}'.")
39
+ report(:warn, i.context(i))
40
+ end
41
+
42
+ tree.all(:Integer).select { |i| i.tokens.first.type == :INT_DEC }.each do |i|
43
+ next if i.value == 0 # Lots of plugins use '00' or '0000', which is ok.
44
+ next if not i.tokens.first.body =~ /^0[0-9]/
45
+ warn
46
+ report(:warn, "This integer appears to be octal, but will be interpreted as decimal.")
47
+ report(:warn, "NASL integers beginning with '0' with all digits between 0-7 are octal.")
48
+ report(:warn, "Remove the leading '0' to make it clear this integer should be decimal.")
49
+ report(:warn, i.context(i))
50
+ end
51
+ end
52
+
53
+ def run
54
+ # This check will pass by default.
55
+ pass
56
+
57
+ # Run this check on the tree from every file.
58
+ @kb[:trees].each { |file, tree| check(file, tree) }
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module Pedant
2
- VERSION = '0.0.9'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,85 @@
1
+ ################################################################################
2
+ # Copyright (c) 2015, Tenable Network Security
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ ################################################################################
26
+
27
+ class TestArityOfBuiltins < Test::Unit::TestCase
28
+ include Pedant::Test
29
+
30
+ def test_none
31
+ check(
32
+ :pass,
33
+ :CheckConditionalContainsAssignment,
34
+ %q||
35
+ )
36
+ end
37
+
38
+ def test_correct
39
+ check(
40
+ :pass,
41
+ :CheckArityOfBuiltins,
42
+ %q|get_kb_item("hello");|
43
+ )
44
+ end
45
+
46
+ def test_no_args
47
+ check(
48
+ :fail,
49
+ :CheckArityOfBuiltins,
50
+ %q|get_kb_item();|
51
+ )
52
+ end
53
+
54
+ def test_named
55
+ check(
56
+ :fail,
57
+ :CheckArityOfBuiltins,
58
+ %q|get_kb_item(key:"hello");|
59
+ )
60
+ end
61
+
62
+ def test_two_anon
63
+ check(
64
+ :fail,
65
+ :CheckArityOfBuiltins,
66
+ %q|get_kb_item("service/", port);|
67
+ )
68
+ end
69
+
70
+ def test_three_anon
71
+ check(
72
+ :fail,
73
+ :CheckArityOfBuiltins,
74
+ %q|get_kb_item("hello/", port, "/property");|
75
+ )
76
+ end
77
+
78
+ def test_one_anon_one_named
79
+ check(
80
+ :fail,
81
+ :CheckArityOfBuiltins,
82
+ %q|get_kb_item("hello/", index:index);|
83
+ )
84
+ end
85
+ end
@@ -0,0 +1,157 @@
1
+ ################################################################################
2
+ # Copyright (c) 2015, Tenable Network Security
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ ################################################################################
26
+
27
+ class TestNonsenseComparison < Test::Unit::TestCase
28
+ include Pedant::Test
29
+
30
+ def test_none
31
+ check(
32
+ :pass,
33
+ :CheckNonsenseComparison,
34
+ %q||
35
+ )
36
+ end
37
+
38
+ def test_isnull_call
39
+ check(
40
+ :pass,
41
+ :CheckNonsenseComparison,
42
+ %q|isnull(recv());|
43
+ )
44
+ end
45
+
46
+ def test_isnull_identifier
47
+ check(
48
+ :pass,
49
+ :CheckNonsenseComparison,
50
+ %q|isnull(some_variable);|
51
+ )
52
+ end
53
+
54
+ def test_isnull_literal_string
55
+ check(
56
+ :fail,
57
+ :CheckNonsenseComparison,
58
+ %q|isnull("hello");|
59
+ )
60
+ end
61
+
62
+ def test_isnull_literal_string
63
+ check(
64
+ :fail,
65
+ :CheckNonsenseComparison,
66
+ %q|isnull(6);|
67
+ )
68
+ end
69
+
70
+ def test_literal_comparison_eq
71
+ check(
72
+ :fail,
73
+ :CheckNonsenseComparison,
74
+ %q|if ("hello" == 5) {};|
75
+ )
76
+ end
77
+
78
+ def test_literal_comparison_substr
79
+ check(
80
+ :fail,
81
+ :CheckNonsenseComparison,
82
+ %q|if ("he" >< "hello") {};|
83
+ )
84
+ end
85
+
86
+ def test_literal_comparison_regex
87
+ check(
88
+ :fail,
89
+ :CheckNonsenseComparison,
90
+ %q|if ("name" =~ "pedant") {};|
91
+ )
92
+ end
93
+
94
+ def test_different_simple
95
+ check(
96
+ :pass,
97
+ :CheckNonsenseComparison,
98
+ %q|if (a == b) {};|
99
+ )
100
+ end
101
+
102
+ def test_same_simple
103
+ check(
104
+ :fail,
105
+ :CheckNonsenseComparison,
106
+ %q|if (a == a) {};|
107
+ )
108
+ end
109
+
110
+ def test_different_indexes
111
+ check(
112
+ :pass,
113
+ :CheckNonsenseComparison,
114
+ %q|if (a[1] == a[2]) {};|
115
+ )
116
+ end
117
+
118
+ def test_same_indexes
119
+ check(
120
+ :fail,
121
+ :CheckNonsenseComparison,
122
+ %q|if (a[1] == a[1]) {};|
123
+ )
124
+ end
125
+
126
+ def test_same_indexes_with_different_base
127
+ check(
128
+ :fail,
129
+ :CheckNonsenseComparison,
130
+ %q|if (a[1] == a[0x01]) {};|
131
+ )
132
+ end
133
+
134
+ def test_multiple_index_types
135
+ check(
136
+ :fail,
137
+ :CheckNonsenseComparison,
138
+ %q|if (a[1]["hello"][b] == a[1]["hello"][b]) {};|
139
+ )
140
+ end
141
+
142
+ def test_indexes_with_other_lvalues
143
+ check(
144
+ :fail,
145
+ :CheckNonsenseComparison,
146
+ %q|if (a[1]["hello"][b.hello["woo"].yay] == a[1]["hello"][b.hello["woo"].yay]) {};|
147
+ )
148
+ end
149
+
150
+ def test_calls
151
+ check(
152
+ :pass,
153
+ :CheckNonsenseComparison,
154
+ %q|if (a[1] == a[0x01]()) {};|
155
+ )
156
+ end
157
+ end
@@ -0,0 +1,85 @@
1
+ ################################################################################
2
+ # Copyright (c) 2015, Tenable Network Security
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ ################################################################################
26
+
27
+ class TestUsesOctalIntegers < Test::Unit::TestCase
28
+ include Pedant::Test
29
+
30
+ def test_none
31
+ check(
32
+ :pass,
33
+ :CheckUsesOctalIntegers,
34
+ %q||
35
+ )
36
+ end
37
+
38
+ def test_octal_literal_integer
39
+ check(
40
+ :warn,
41
+ :CheckUsesOctalIntegers,
42
+ %q|if (a = 057) { exit(); }|
43
+ )
44
+ end
45
+
46
+ def test_nearly_octal_integer
47
+ check(
48
+ :warn,
49
+ :CheckUsesOctalIntegers,
50
+ %q|if (a = 099) { exit(); }|
51
+ )
52
+ end
53
+
54
+ def test_octal_all_zeroes_short
55
+ check(
56
+ :pass,
57
+ :CheckUsesOctalIntegers,
58
+ %q|if (a = 00) { exit(); }|
59
+ )
60
+ end
61
+
62
+ def test_octal_all_zeroes_longer
63
+ check(
64
+ :pass,
65
+ :CheckUsesOctalIntegers,
66
+ %q|if (a = 000000) { exit(); }|
67
+ )
68
+ end
69
+
70
+ def test_decimal_literal
71
+ check(
72
+ :pass,
73
+ :CheckUsesOctalIntegers,
74
+ %q|if (a = 10) { exit(); }|
75
+ )
76
+ end
77
+
78
+ def test_hexadecimal_literal
79
+ check(
80
+ :pass,
81
+ :CheckUsesOctalIntegers,
82
+ %q|if (a = 0x10) { exit(); }|
83
+ )
84
+ end
85
+ 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.0.9
4
+ version: 0.1.0
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: 2015-06-23 00:00:00.000000000 Z
13
+ date: 2015-09-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -77,6 +77,7 @@ files:
77
77
  - bin/pedant
78
78
  - lib/pedant.rb
79
79
  - lib/pedant/check.rb
80
+ - lib/pedant/checks/arity_of_builtins.rb
80
81
  - lib/pedant/checks/conditional_contains_assignment.rb
81
82
  - lib/pedant/checks/conditional_or_loop_is_empty.rb
82
83
  - lib/pedant/checks/confusing_variable_names.rb
@@ -90,6 +91,7 @@ files:
90
91
  - lib/pedant/checks/files_parse_without_errors.rb
91
92
  - lib/pedant/checks/flipped_operands_on_match_or_substring.rb
92
93
  - lib/pedant/checks/local_variable_unused.rb
94
+ - lib/pedant/checks/nonsense_comparison.rb
93
95
  - lib/pedant/checks/parse_test_code.rb
94
96
  - lib/pedant/checks/plugin_type_not_specified.rb
95
97
  - lib/pedant/checks/script_category.rb
@@ -97,6 +99,7 @@ files:
97
99
  - lib/pedant/checks/script_id.rb
98
100
  - lib/pedant/checks/script_name.rb
99
101
  - lib/pedant/checks/script_summary.rb
102
+ - lib/pedant/checks/uses_octal_integers.rb
100
103
  - lib/pedant/cli.rb
101
104
  - lib/pedant/command.rb
102
105
  - lib/pedant/commands/check.rb
@@ -106,6 +109,7 @@ files:
106
109
  - lib/pedant/version.rb
107
110
  - pedant.gemspec
108
111
  - test/test_helper.rb
112
+ - test/unit/checks/test_arity_of_builtins.rb
109
113
  - test/unit/checks/test_conditional_contains_assignment.rb
110
114
  - test/unit/checks/test_conditional_or_loop_is_empty.rb
111
115
  - test/unit/checks/test_confusing_variable_names.rb
@@ -117,8 +121,10 @@ files:
117
121
  - test/unit/checks/test_ends_with_newline.rb
118
122
  - test/unit/checks/test_equality_with_regex.rb
119
123
  - test/unit/checks/test_flipped_operands_on_match_or_substring.rb
124
+ - test/unit/checks/test_nonsense_comparison.rb
120
125
  - test/unit/checks/test_plugin_type_not_specified.rb
121
126
  - test/unit/checks/test_script_family_not_specified.rb
127
+ - test/unit/checks/test_uses_octal_integers.rb
122
128
  homepage: http://github.com/tenable/pedant
123
129
  licenses:
124
130
  - BSD
@@ -145,6 +151,7 @@ specification_version: 4
145
151
  summary: A framework for the Nessus Attack Scripting Language.
146
152
  test_files:
147
153
  - test/test_helper.rb
154
+ - test/unit/checks/test_arity_of_builtins.rb
148
155
  - test/unit/checks/test_conditional_contains_assignment.rb
149
156
  - test/unit/checks/test_conditional_or_loop_is_empty.rb
150
157
  - test/unit/checks/test_confusing_variable_names.rb
@@ -156,5 +163,7 @@ test_files:
156
163
  - test/unit/checks/test_ends_with_newline.rb
157
164
  - test/unit/checks/test_equality_with_regex.rb
158
165
  - test/unit/checks/test_flipped_operands_on_match_or_substring.rb
166
+ - test/unit/checks/test_nonsense_comparison.rb
159
167
  - test/unit/checks/test_plugin_type_not_specified.rb
160
168
  - test/unit/checks/test_script_family_not_specified.rb
169
+ - test/unit/checks/test_uses_octal_integers.rb