Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/openssl/buffering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def readbyte
# See IO#read for full details.

def read(size=nil, buf=nil)
raise ArgumentError, "negative length #{size} given" if size && size < 0

if size == 0
if buf
buf.clear
Expand Down Expand Up @@ -143,6 +145,8 @@ def read(size=nil, buf=nil)
# See IO#readpartial for full details.

def readpartial(maxlen, buf=nil)
raise ArgumentError, "negative length #{maxlen} given" if maxlen < 0

if maxlen == 0
if buf
buf.clear
Expand Down Expand Up @@ -201,6 +205,8 @@ def readpartial(maxlen, buf=nil)
# it will return +nil+ instead of raising EOFError.

def read_nonblock(maxlen, buf=nil, exception: true)
raise ArgumentError, "negative length #{maxlen} given" if maxlen < 0

if maxlen == 0
if buf
buf.clear
Expand Down Expand Up @@ -232,9 +238,11 @@ def read_nonblock(maxlen, buf=nil, exception: true)
# Unlike IO#gets the separator must be provided if a limit is provided.

def gets(eol=$/, limit=nil, chomp: false)
return "" if limit == 0

idx = @rbuffer.index(eol)
until @eof
break if idx
break if idx || (limit && limit > 0 && @rbuffer.bytesize >= limit)
fill_rbuff
idx = @rbuffer.index(eol)
end
Expand All @@ -243,8 +251,8 @@ def gets(eol=$/, limit=nil, chomp: false)
else
size = idx ? idx+eol.size : nil
end
if size && limit && limit >= 0
size = [size, limit].min
if limit && limit >= 0
size = [size || @rbuffer.bytesize, limit].min
end
line = consume_rbuff(size)
if chomp && line
Expand Down