summaryrefslogtreecommitdiff
path: root/lib/ipaddr.rb
diff options
context:
space:
mode:
authorKasumi Hanazuki <[email protected]>2023-11-27 04:15:48 +0000
committerHiroshi SHIBATA <[email protected]>2023-12-25 21:12:49 +0900
commiteb53131367d6e1d3da16b0cd6bc44284ea3589ea ()
tree1b969044254962728adbaa1fcc08f92f16b83170 /lib/ipaddr.rb
parentea5776e7e4262c915f7f8b8884af420dd87d769c (diff)
[ruby/ipaddr] ntop: Measure address size in bytes
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this makes it an explicit error with an `InvalidAddressError`. Fixes: https://.com/ruby/ipaddr/issues/56 https://.com/ruby/ipaddr/commit/a33fd14d4a
-rw-r--r--lib/ipaddr.rb7
1 files changed, 6 insertions, 1 deletions
@@ -110,8 +110,13 @@ class IPAddr
# Convert a network byte ordered string form of an IP address into
# human readable form.
def self.ntop(addr)
- case addr.size
when 4
addr.unpack('C4').join('.')
when 16