Ensure checksum* methods return a Fixnum

Fixes a bug in reverse_http* stagers where requests for the root URI
(i.e., "/") cause a NoMethodError on nil returned by checksum8.

[See #2216]
bug/bundler_fix
James Lee 2013-08-14 14:09:37 -05:00
parent 163c13526d
commit ed00b8c19e
1 changed files with 15 additions and 5 deletions

View File

@ -1563,24 +1563,34 @@ protected
@@codepage_map_cache = map
end
# @param str [String] Data to checksum
# @return [Fixnum] 8-bit checksum
def self.checksum8(str)
str.unpack("C*").inject(:+) % 0x100
(str.unpack("C*").inject(:+) || 0) % 0x100
end
# @param str [String] Little-endian data to checksum
# @return [Fixnum] 16-bit checksum
def self.checksum16_le(str)
str.unpack("v*").inject(:+) % 0x10000
(str.unpack("v*").inject(:+) || 0) % 0x10000
end
# @param str [String] Big-endian data to checksum
# @return [Fixnum] 16-bit checksum
def self.checksum16_be(str)
str.unpack("n*").inject(:+) % 0x10000
(str.unpack("n*").inject(:+) || 0) % 0x10000
end
# @param str [String] Little-endian data to checksum
# @return [Fixnum] 32-bit checksum
def self.checksum32_le(str)
str.unpack("V*").inject(:+) % 0x100000000
(str.unpack("V*").inject(:+) || 0) % 0x100000000
end
# @param str [String] Big-endian data to checksum
# @return [Fixnum] 32-bit checksum
def self.checksum32_be(str)
str.unpack("N*").inject(:+) % 0x100000000
(str.unpack("N*").inject(:+) || 0) % 0x100000000
end
end