summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Hunt <chrahunt@gmail.com>2014-05-11 19:40:18 -0400
committerChristopher Hunt <chrahunt@gmail.com>2014-05-11 19:40:18 -0400
commit443d04992407dc24731895141f7431720ba1d2a6 (patch)
treecb5fe5a0051aa5bc800b03062430e8aa14dbf0e1
parentb3b2ec3e315c3f3b36b8438047ccbca08ca48e13 (diff)
downloadnet-ssh-443d04992407dc24731895141f7431720ba1d2a6.tar.gz
Clearer C string handling.
-rw-r--r--lib/net/ssh/authentication/pageant.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/net/ssh/authentication/pageant.rb b/lib/net/ssh/authentication/pageant.rb
index 885054f..4b89e55 100644
--- a/lib/net/ssh/authentication/pageant.rb
+++ b/lib/net/ssh/authentication/pageant.rb
@@ -256,6 +256,11 @@ module Net; module SSH; module Authentication
raise "Windows error: #{Win.GetLastError}"
end
end
+
+ # Get a null-terminated string given a string.
+ def self.get_cstr(str)
+ return str + "\000"
+ end
end
# This is the pseudo-socket implementation that mimics the interface of
@@ -323,7 +328,7 @@ module Net; module SSH; module Authentication
ptr = nil
id = Win.malloc_ptr(Win::SIZEOF_DWORD)
- mapname = "PageantRequest%08x\000" % Win.GetCurrentThreadId()
+ mapname = "PageantRequest%08x" % Win.GetCurrentThreadId()
security_attributes = Win.get_ptr Win.get_security_attributes_for_user
filemap = Win.CreateFileMapping(Win::INVALID_HANDLE_VALUE,
@@ -344,13 +349,9 @@ module Net; module SSH; module Authentication
end
Win.set_ptr_data(ptr, query)
-
- # The second element should be (mapname.size + 1) to mirror the
- # implementation in PuTTY/Pageant. Because strlen in C does not
- # count null-terminator but String#size in Ruby does, we will
- # leave it as-is and call it even.
- cds = Win.get_ptr [AGENT_COPYDATA_ID, mapname.size,
- mapname].pack("LLp")
+
+ cds = Win.get_ptr [AGENT_COPYDATA_ID, mapname.size + 1,
+ Win.get_cstr(mapname)].pack("LLp")
succ = Win.SendMessageTimeout(@win, Win::WM_COPYDATA, Win::NULL,
cds, Win::SMTO_NORMAL, 5000, id)