Class: Police::Labels::UnsafeStream

Inherits:
DataFlow::Label
  • Object
show all
Defined in:
lib/police/labels/unsafe_stream.rb

Overview

Adds a label to any data read from a IO stream.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unsafe_label) ⇒ UnsafeStream

Returns a new instance of UnsafeStream.

Parameters:

  • unsafe_label (Police::DataFlow::Label)

    the label that will be added to the stream’s data



9
10
11
# File 'lib/police/labels/unsafe_stream.rb', line 9

def initialize(unsafe_label)
  @label = unsafe_label
end

Class Method Details

.autoflow?Boolean

Returns:

  • (Boolean)

See Also:

  • DataFlow::Label#autoflow?


14
15
16
# File 'lib/police/labels/unsafe_stream.rb', line 14

def self.autoflow?
  false
end

.return_hook(method_name) ⇒ Object

See Also:

  • DataFlow::Label#return_hook


24
25
26
27
28
29
30
31
# File 'lib/police/labels/unsafe_stream.rb', line 24

def self.return_hook(method_name)
  case method_name
  when :read
    :read
  else
    nil
  end
end

.yield_args_hook(method_name) ⇒ Object

See Also:

  • DataFlow::Label#yield_args_hook


34
35
36
# File 'lib/police/labels/unsafe_stream.rb', line 34

def self.yield_args_hook(method_name)
  nil
end

Instance Method Details

#accepts?(data) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • DataFlow::Label#accepts?


19
20
21
# File 'lib/police/labels/unsafe_stream.rb', line 19

def accepts?(data)
  data.kind_of?(IO) || data.kind_of?(StringIO)
end

#read(return_value, receiver, *args) ⇒ Object

Adds a label to the read’s return value.

See Also:

  • IO#read


40
41
42
# File 'lib/police/labels/unsafe_stream.rb', line 40

def read(return_value, receiver, *args)
  Police::DataFlow.label return_value, @label
end