From d7eb5b6638730c492cfa4355dcc292e60d990bd0 Mon Sep 17 00:00:00 2001 From: Sophie Brun Date: Fri, 4 Sep 2020 17:31:15 +0200 Subject: [PATCH] Fix Capturing the given block using Kernel#proc --- server/libs/dnser.rb | 10 +++++----- server/libs/settings.rb | 4 ++-- server/libs/swindow.rb | 8 ++++---- server/tunnel_drivers/driver_dns.rb | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/server/libs/dnser.rb b/server/libs/dnser.rb index 0af84aea..cb167348 100644 --- a/server/libs/dnser.rb +++ b/server/libs/dnser.rb @@ -837,7 +837,7 @@ def initialize(host, port, cache=false) # This method returns immediately, but spawns a background thread. The thread # will recveive and parse DNS packets, create a transaction, and pass it to # the caller's block. - def on_request() + def on_request(&block) @thread = Thread.new() do |t| begin loop do @@ -869,7 +869,7 @@ def on_request() if(!transaction.sent) begin - proc.call(transaction) + block.call(transaction) rescue StandardError => e puts("Caught an error: #{e}") puts(e.backtrace()) @@ -912,7 +912,7 @@ def wait() # Send out a query, asynchronously. This immediately returns, then, when the # query is finished, the callback block is called with a DNSer::Packet that # represents the response (or nil, if there was a timeout). - def DNSer.query(hostname, params = {}) + def DNSer.query(hostname, params = {}, &block) server = params[:server] || "8.8.8.8" port = params[:port] || 53 type = params[:type] || DNSer::Packet::TYPE_A @@ -930,10 +930,10 @@ def DNSer.query(hostname, params = {}) timeout(timeout) do response = s.recv(65536) - proc.call(DNSer::Packet.parse(response)) + block.call(DNSer::Packet.parse(response)) end rescue Timeout::Error - proc.call(nil) + block.call(nil) rescue Exception => e puts("There was an exception sending a query for #{hostname} to #{server}:#{port}: #{e}") ensure diff --git a/server/libs/settings.rb b/server/libs/settings.rb index 64882382..7fb5dafe 100644 --- a/server/libs/settings.rb +++ b/server/libs/settings.rb @@ -157,13 +157,13 @@ def each_setting() # Create a new setting, or replace an old one. This must be done before a # setting is used. - def create(name, type, default_value, docs) + def create(name, type, default_value, docs, &block) name = name.to_s() @settings[name] = @settings[name] || {} @settings[name][:type] = type - @settings[name][:watcher] = proc + @settings[name][:watcher] = block @settings[name][:docs] = docs @settings[name][:default] = @@mutators[type].call(default_value.to_s()) diff --git a/server/libs/swindow.rb b/server/libs/swindow.rb index 3095a48a..9292c924 100644 --- a/server/libs/swindow.rb +++ b/server/libs/swindow.rb @@ -60,14 +60,14 @@ class SWindow # This function will trap the TSTP signal (suspend, ctrl-z) and, if possible, # activate the parent window. - def SWindow._catch_suspend() + def SWindow._catch_suspend(&block) orig_suspend = Signal.trap("TSTP") do if(@@active) @@active.deactivate() end end - proc.call() + block.call() Signal.trap("TSTP", orig_suspend) end @@ -182,8 +182,8 @@ def children() # Set the on_input callback - the function that will be called when input is # received. Very important! - def on_input() - @callback = proc + def on_input(&block) + @callback = block end def with(params = {}) diff --git a/server/tunnel_drivers/driver_dns.rb b/server/tunnel_drivers/driver_dns.rb index f4e778e6..100010ea 100644 --- a/server/tunnel_drivers/driver_dns.rb +++ b/server/tunnel_drivers/driver_dns.rb @@ -242,7 +242,7 @@ def DriverDNS.do_encoding(question, domains, response) return response end - def initialize(parent_window, host, port, domains, cache) + def initialize(parent_window, host, port, domains, cache, &block) if(domains.nil?) domains = [] end @@ -313,7 +313,7 @@ def initialize(parent_window, host, port, domains, cache) end # Get the response - response = proc.call(name, max_length) + response = block.call(name, max_length) if(response.length > max_length) raise(DnscatException, "The handler returned too much data! This shouldn't happen, please report. (max = #{max_length}, returned = #{response.length}")