nasl 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 199cd9a0ada92765a2e1812786f7b41eb22c3724
4
- data.tar.gz: 0b8ff7ebf8d1b4b166dd7ffb4f71fa52d884e1aa
3
+ metadata.gz: 8dbfbd10777b11f9eb32bfa1852b114e4ba027b8
4
+ data.tar.gz: 3adae20946d690b72b6cce0378ec3bb36cf6ec90
5
5
  SHA512:
6
- metadata.gz: 1cd9093af658c23660d9d662e3da33ab2ecaf97aececd1402832a92a7d779e245c2a64c7cfe1be8d71793f2f08b2f51388e03de1d2a5be0da7712bc541a6a8ab
7
- data.tar.gz: 749a6d9e4fea7edb88eb34113496988d7cba0cfe6baffb00eeabc154a4f81ffddd2d93eccbff44b142f645d2f190f7c88559bf77d892cd9bacd5f2ac42d9801e
6
+ metadata.gz: 3f58cb329f9293ef5e32f130864af3e48fd07d66555866c1ede44c719fcbc88d8c6e1781a9bcac5b261a2b26a320b5231c865697126d4853276c7bb7decf7225
7
+ data.tar.gz: 4fb81fb4ba0a4c54d2df014a423578bb53cb3eb6ba1acda35e24df4cb3440e40a7eee2070b07dc98790f98757ecc03079392cb1dfb13e2cf8fc4f5c3c1fed18a
@@ -168,6 +168,8 @@ rule
168
168
  { val[0] }
169
169
  | foreach
170
170
  { val[0] }
171
+ | do_while
172
+ { val[0] }
171
173
  | if
172
174
  { val[0] }
173
175
  | repeat
@@ -295,7 +297,7 @@ rule
295
297
  ;
296
298
 
297
299
  case_expr_list : case_expr
298
- { val[0] }
300
+ { [val[0]] }
299
301
  | case_expr COMMA case_expr_list
300
302
  { [val[0]] + val[2] }
301
303
  ;
@@ -314,6 +316,16 @@ rule
314
316
  { n(:Foreach, val[0], val[1], val[3], val[5]) }
315
317
  | FOREACH LPAREN ident IN expr RPAREN statement
316
318
  { n(:Foreach, val[0], val[2], val[4], val[6]) }
319
+ | FOREACH LPAREN VAR ident IN expr RPAREN statement
320
+ { n(:Foreach, val[0], val[3], val[5], val[7]) }
321
+ | FOR LPAREN VAR ident IN expr RPAREN statement
322
+ { n(:Foreach, val[0], val[3], val[5], val[7]) }
323
+ | FOR LPAREN ident IN expr RPAREN statement
324
+ { n(:Foreach, val[0], val[2], val[4], val[6]) }
325
+ ;
326
+
327
+ do_while : DO statement WHILE LPAREN expr RPAREN
328
+ { n(:DoWhile, *val) }
317
329
  ;
318
330
 
319
331
  if : IF LPAREN expr RPAREN statement
@@ -482,11 +494,11 @@ rule
482
494
  { val[0] }
483
495
  ;
484
496
 
485
-
486
497
  ident_ex : ident
487
498
  { val[0] }
488
499
  | VAR
489
500
  { val[0] }
501
+ ;
490
502
 
491
503
  ##############################################################################
492
504
  # Named Components
@@ -532,6 +544,10 @@ rule
532
544
 
533
545
  ref : AT_SIGN ident
534
546
  { n(:Reference, val[1]) }
547
+ | FUNCTION LPAREN params RPAREN block
548
+ { n(:FunctionReference, val[2], val[4]) }
549
+ | FUNCTION LPAREN RPAREN block
550
+ { n(:FunctionReference, val[3]) }
535
551
  ;
536
552
 
537
553
  ##############################################################################
@@ -582,6 +598,8 @@ rule
582
598
 
583
599
  list_elems : list_elem COMMA list_elems
584
600
  { [val[0]] + val[2] }
601
+ | list_elem COMMA
602
+ { [val[0]] }
585
603
  | list_elem
586
604
  { [val[0]] }
587
605
  ;
@@ -644,6 +662,16 @@ rule
644
662
  { n(:Identifier, *val) }
645
663
  | IN
646
664
  { n(:Identifier, *val) }
665
+ | OBJECT
666
+ { n(:Identifier, *val) }
667
+ | CONTINUE
668
+ { n(:Identifier, *val) }
669
+ | PUBLIC
670
+ { n(:Identifier, *val) }
671
+ | PRIVATE
672
+ { n(:Identifier, *val) }
673
+ | DEFAULT
674
+ { n(:Identifier, *val) }
647
675
  ;
648
676
 
649
677
  int : INT_DEC
@@ -716,6 +744,8 @@ require 'nasl/parser/object'
716
744
  require 'nasl/parser/switch'
717
745
  require 'nasl/parser/case'
718
746
  require 'nasl/parser/obj_var'
747
+ require 'nasl/parser/do_while'
748
+ require 'nasl/parser/function_ref'
719
749
 
720
750
  ---- inner ----
721
751
 
@@ -0,0 +1,43 @@
1
+ ################################################################################
2
+ # Copyright (c) 2011-2018, 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 'nasl/parser/node'
28
+
29
+ module Nasl
30
+ class DoWhile < Node
31
+ attr_reader :body, :cond
32
+
33
+ def initialize(tree, *tokens)
34
+ super
35
+
36
+ @cond = @tokens[4]
37
+ @body = @tokens[1]
38
+
39
+ @children << :cond
40
+ @children << :body
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2014, Tenable Network Security
2
+ # Copyright (c) 2011-2018, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -0,0 +1,52 @@
1
+ ################################################################################
2
+ # Copyright (c) 2011-2018, 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 'nasl/parser/node'
28
+
29
+ module Nasl
30
+ class FunctionReference < Node
31
+ attr_reader :body, :params
32
+
33
+ def initialize(tree, *tokens)
34
+ super
35
+
36
+ @body = @tokens.last
37
+
38
+ if @tokens.length == 5
39
+ @params = @tokens[0]
40
+ else
41
+ @params = []
42
+ end
43
+
44
+ @children << :params
45
+ @children << :body
46
+ end
47
+
48
+ def each
49
+ @body.each{ |stmt| yield stmt }
50
+ end
51
+ end
52
+ end
@@ -43,7 +43,8 @@ module Nasl
43
43
  case @type
44
44
  when *[:BREAK, :CONTINUE, :ELSE, :EXPORT, :FOR, :FOREACH, :FUNCTION,
45
45
  :GLOBAL, :IF, :IMPORT, :INCLUDE, :LOCAL, :REPEAT, :RETURN, :UNTIL,
46
- :REP, :WHILE, :NAMESPACE, :OBJECT, :VAR, :PUBLIC, :PRIVATE, :CASE, :SWITCH, :DEFAULT]
46
+ :REP, :WHILE, :NAMESPACE, :OBJECT, :VAR, :PUBLIC, :PRIVATE, :CASE,
47
+ :SWITCH, :DEFAULT, :DO]
47
48
  "a keyword"
48
49
  when :UNDEF
49
50
  "an undefined constant"
@@ -50,6 +50,7 @@ module Nasl
50
50
  'until' => :UNTIL,
51
51
  'x' => :REP,
52
52
  'while' => :WHILE,
53
+ 'do' => :DO,
53
54
  'namespace' => :NAMESPACE,
54
55
  'object' => :OBJECT,
55
56
  # 'new' => :NEW,
@@ -220,7 +221,8 @@ module Nasl
220
221
  def get_identifier
221
222
  # Identifiers are composed of letters, digits, and underscores.
222
223
  #ident = @line[/^[_a-z][_a-z0-9]*/i]
223
- ident = @line[/^[_a-z]([_a-z0-9]*::[_a-z0-9]+)*[_a-z0-9]*/i]
224
+ # ident = @line[/^[_a-z]([_a-z0-9]*::[_a-z0-9]+)*[_a-z0-9]*/i]
225
+ ident = @line[/^(::|[_a-z])([_a-z0-9]*::[_a-z0-9]+)*[_a-z0-9]*/i]
224
226
  consume(ident.length)
225
227
 
226
228
  # Assume that we've got an identifier until proven otherwise.
@@ -371,7 +373,7 @@ module Nasl
371
373
  @mark = @point
372
374
 
373
375
  # Try to parse token at the point.
374
- token = if @char =~ /[_a-z]/i
376
+ token = if @char =~ /[_a-z]/i or @line =~ /^::/
375
377
  get_identifier
376
378
  elsif @char =~ /['"]/
377
379
  get_string
@@ -25,5 +25,5 @@
25
25
  ################################################################################
26
26
 
27
27
  module Nasl
28
- VERSION = '0.4.0'
28
+ VERSION = '0.5.0'
29
29
  end
@@ -30,7 +30,6 @@ class TestCall < Test::Unit::TestCase
30
30
  def test_keyword_prefix
31
31
  # We never want to have a function with the same name as a keyword.
32
32
  fail_parse("break();")
33
- fail_parse("continue();")
34
33
  fail_parse("else();")
35
34
  fail_parse("export();")
36
35
  fail_parse("for();")
@@ -0,0 +1,46 @@
1
+ ################################################################################
2
+ # Copyright (c) 2011-2018, 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 TestDoWhile < Test::Unit::TestCase
28
+ include Nasl::Test
29
+
30
+ def test_each
31
+ tree = parse(
32
+ <<-EOF
33
+ x = 0;
34
+ do
35
+ {
36
+ x ++;
37
+ display(x);
38
+ }
39
+ while (x < 10)
40
+ EOF
41
+ )
42
+ do_whiles = tree.all(:DoWhile)
43
+ assert_not_nil(tree)
44
+ assert_equal(1, do_whiles.length)
45
+ end
46
+ end
@@ -30,7 +30,6 @@ class TestFunction < Test::Unit::TestCase
30
30
  def test_keyword_prefix
31
31
  # We never want to have a function with the same name as a keyword.
32
32
  fail_parse("function break() {}")
33
- fail_parse("function continue() {}")
34
33
  fail_parse("function else() {}")
35
34
  fail_parse("function export() {}")
36
35
  fail_parse("function for() {}")
@@ -61,6 +61,13 @@ switch (value2)
61
61
  break;
62
62
  default:
63
63
  rtrn = 1;
64
+ }
65
+ switch (value3)
66
+ {
67
+ case ' ', '\n', '\t', '\r':
68
+ return TRUE;
69
+ default:
70
+ return FALSE;
64
71
  }
65
72
  EOF
66
73
  )
@@ -68,14 +75,16 @@ switch (value2)
68
75
 
69
76
  cases = tree.all(:Case)
70
77
  assert_not_nil(cases)
71
- assert_equal(9, cases.length)
78
+ assert_equal(11, cases.length)
72
79
 
73
80
  assert_equal(cases[0].case_op, nil)
74
81
  assert_equal(cases[6].case_op.to_s, "=~")
75
82
 
76
- assert_equal(cases[0].case_val.value, 0)
77
- assert_equal(cases[4].case_val.text, "^cde.*")
83
+ assert_equal(cases[0].case_val[0].value, 0)
84
+ assert_equal(cases[4].case_val[0].text, "^cde.*")
85
+ assert_equal(cases[9].case_val[0].text, " ")
78
86
  assert_equal(cases[2].case_val, nil)
87
+ assert_equal(cases[9].case_val[2].text, "\t")
79
88
 
80
89
  assert_equal(cases[6].case_type, "normal_with_op")
81
90
  assert_equal(cases[0].case_type, "normal")
@@ -84,7 +93,7 @@ switch (value2)
84
93
 
85
94
  switches = tree.all(:Switch)
86
95
  assert_not_nil(switches)
87
- assert_equal(3, switches.length)
96
+ assert_equal(4, switches.length)
88
97
 
89
98
  assert_equal(switches[1].switch_op.to_s, "=~")
90
99
  assert_equal(switches[0].switch_op, nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nasl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.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: 2018-06-01 00:00:00.000000000 Z
13
+ date: 2018-06-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: racc
@@ -121,12 +121,14 @@ files:
121
121
  - lib/nasl/parser/comment.rb
122
122
  - lib/nasl/parser/continue.rb
123
123
  - lib/nasl/parser/decrement.rb
124
+ - lib/nasl/parser/do_while.rb
124
125
  - lib/nasl/parser/empty.rb
125
126
  - lib/nasl/parser/export.rb
126
127
  - lib/nasl/parser/expression.rb
127
128
  - lib/nasl/parser/for.rb
128
129
  - lib/nasl/parser/foreach.rb
129
130
  - lib/nasl/parser/function.rb
131
+ - lib/nasl/parser/function_ref.rb
130
132
  - lib/nasl/parser/global.rb
131
133
  - lib/nasl/parser/identifier.rb
132
134
  - lib/nasl/parser/if.rb
@@ -166,6 +168,7 @@ files:
166
168
  - test/unit/parser/test_call.rb
167
169
  - test/unit/parser/test_comment.rb
168
170
  - test/unit/parser/test_constant.rb
171
+ - test/unit/parser/test_do_while.rb
169
172
  - test/unit/parser/test_empty.rb
170
173
  - test/unit/parser/test_expressions.rb
171
174
  - test/unit/parser/test_foreach.rb
@@ -225,6 +228,7 @@ test_files:
225
228
  - test/unit/parser/test_call.rb
226
229
  - test/unit/parser/test_comment.rb
227
230
  - test/unit/parser/test_constant.rb
231
+ - test/unit/parser/test_do_while.rb
228
232
  - test/unit/parser/test_empty.rb
229
233
  - test/unit/parser/test_expressions.rb
230
234
  - test/unit/parser/test_foreach.rb