diff options
Diffstat (limited to 'lib/net/ssh')
-rw-r--r-- | lib/net/ssh/authentication/ed25519.rb | 2 | ||||
-rw-r--r-- | lib/net/ssh/buffer.rb | 13 | ||||
-rw-r--r-- | lib/net/ssh/config.rb | 2 | ||||
-rw-r--r-- | lib/net/ssh/connection/session.rb | 4 | ||||
-rw-r--r-- | lib/net/ssh/proxy/jump.rb | 2 | ||||
-rw-r--r-- | lib/net/ssh/transport/ctr.rb | 8 | ||||
-rw-r--r-- | lib/net/ssh/transport/server_version.rb | 4 | ||||
-rw-r--r-- | lib/net/ssh/transport/state.rb | 2 |
8 files changed, 21 insertions, 16 deletions
diff --git a/lib/net/ssh/authentication/ed25519.rb b/lib/net/ssh/authentication/ed25519.rb index 1da9389..0c5bdf2 100644 --- a/lib/net/ssh/authentication/ed25519.rb +++ b/lib/net/ssh/authentication/ed25519.rb @@ -116,7 +116,7 @@ module Net end def to_blob - Net::SSH::Buffer.from(:mstring,"ssh-ed25519",:string,@verify_key.to_bytes).to_s + Net::SSH::Buffer.from(:mstring,"ssh-ed25519".dup,:string,@verify_key.to_bytes).to_s end def ssh_type diff --git a/lib/net/ssh/buffer.rb b/lib/net/ssh/buffer.rb index b27fc5d..3934ae7 100644 --- a/lib/net/ssh/buffer.rb +++ b/lib/net/ssh/buffer.rb @@ -70,7 +70,7 @@ module Net # Creates a new buffer, initialized to the given content. The position # is initialized to the beginning of the buffer. - def initialize(content="") + def initialize(content=String.new) @content = content.to_s @position = 0 end @@ -117,7 +117,7 @@ module Net # Resets the buffer, making it empty. Also, resets the read position to # 0. def clear! - @content = "" + @content = String.new @position = 0 end @@ -133,7 +133,7 @@ module Net # optimize for a fairly common case clear! elsif n > 0 - @content = @content[n..-1] || "" + @content = @content[n..-1] || String.new @position -= n @position = 0 if @position < 0 end @@ -346,7 +346,12 @@ module Net # Optimized version of write where the caller gives up ownership of string # to the method. This way we can mutate the string. def write_moved(string) - @content << string.force_encoding('BINARY') + @content << + if string.frozen? + string.dup.force_encoding('BINARY') + else + string.force_encoding('BINARY') + end self end diff --git a/lib/net/ssh/config.rb b/lib/net/ssh/config.rb index 6aac71a..98714e4 100644 --- a/lib/net/ssh/config.rb +++ b/lib/net/ssh/config.rb @@ -299,7 +299,7 @@ module Net # host names. def pattern2regex(pattern) tail = pattern - prefix = "" + prefix = String.new while !tail.empty? do head,sep,tail = tail.partition(/[\*\?]/) prefix = prefix + Regexp.quote(head) diff --git a/lib/net/ssh/connection/session.rb b/lib/net/ssh/connection/session.rb index 43546fa..4f09fc8 100644 --- a/lib/net/ssh/connection/session.rb +++ b/lib/net/ssh/connection/session.rb @@ -419,7 +419,7 @@ module Net # the returned string has an exitstatus method to query it's exit satus def exec!(command, status: nil, &block) block_or_concat = block || Proc.new do |ch, type, data| - ch[:result] ||= "" + ch[:result] ||= String.new ch[:result] << data end @@ -427,7 +427,7 @@ module Net channel = exec(command, status: status, &block_or_concat) channel.wait - channel[:result] ||= "" unless block + channel[:result] ||= String.new unless block channel[:result] &&= channel[:result].force_encoding("UTF-8") unless block StringWithExitstatus.new(channel[:result], status[:exit_code]) if channel[:result] diff --git a/lib/net/ssh/proxy/jump.rb b/lib/net/ssh/proxy/jump.rb index 0630bd8..a5de7d9 100644 --- a/lib/net/ssh/proxy/jump.rb +++ b/lib/net/ssh/proxy/jump.rb @@ -38,7 +38,7 @@ module Net config = connection_options && connection_options[:config] uri = URI.parse("ssh://#{first_jump}") - template = "ssh" + template = "ssh".dup template << " -l #{uri.user}" if uri.user template << " -p #{uri.port}" if uri.port template << " -J #{extra_jumps}" if extra_jumps diff --git a/lib/net/ssh/transport/ctr.rb b/lib/net/ssh/transport/ctr.rb index d952a86..9c67aff 100644 --- a/lib/net/ssh/transport/ctr.rb +++ b/lib/net/ssh/transport/ctr.rb @@ -32,7 +32,7 @@ module Net::SSH::Transport module CTR def self.extended(orig) orig.instance_eval { - @remaining = "" + @remaining = String.new @counter = nil @counter_len = orig.block_size orig.encrypt @@ -67,13 +67,13 @@ module Net::SSH::Transport end def reset - @remaining = "" + @remaining = String.new end def update(data) @remaining += data - encrypted = "" + encrypted = String.new offset = 0 while (@remaining.bytesize - offset) >= block_size @@ -89,7 +89,7 @@ module Net::SSH::Transport def final s = @remaining.empty? ? '' : xor!(@remaining, _update(@counter)) - @remaining = "" + @remaining = String.new s end diff --git a/lib/net/ssh/transport/server_version.rb b/lib/net/ssh/transport/server_version.rb index 82de8b0..50ffb15 100644 --- a/lib/net/ssh/transport/server_version.rb +++ b/lib/net/ssh/transport/server_version.rb @@ -27,7 +27,7 @@ module Net # Instantiates a new ServerVersion and immediately (and synchronously) # negotiates the SSH protocol in effect, using the given socket. def initialize(socket, logger, timeout = nil) - @header = "" + @header = String.new @version = nil @logger = logger negotiate!(socket, timeout) @@ -48,7 +48,7 @@ module Net raise Net::SSH::ConnectionTimeout, "timeout during server version negotiating" if timeout && !IO.select([socket], nil, nil, timeout) loop do - @version = "" + @version = String.new loop do begin b = socket.readpartial(1) diff --git a/lib/net/ssh/transport/state.rb b/lib/net/ssh/transport/state.rb index 8f5fd8f..b472191 100644 --- a/lib/net/ssh/transport/state.rb +++ b/lib/net/ssh/transport/state.rb @@ -64,7 +64,7 @@ module Net @hmac = HMAC.get("none") @compression = nil @compressor = @decompressor = nil - @next_iv = "" + @next_iv = String.new end # A convenience method for quickly setting multiple values in a single |