Skip to content

Commit

Permalink
ext/socket: BasicSocket#sendfile will raise an exception if negative …
Browse files Browse the repository at this point in the history
…value passed.
  • Loading branch information
Watson1978 committed Dec 7, 2011
1 parent 6873fae commit 32b6ef3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/socket/socket.c
Expand Up @@ -3071,6 +3071,10 @@ socket_sendfile(VALUE self, SEL sel, VALUE file, VALUE offset, VALUE len)
off_t to_write = NUM2OFFT(len);
rb_io_t *socket;

if (to_offset < 0 || to_write < 0) {
rb_raise(rb_eArgError, "negative argument");
}

GetOpenFile(self, socket);
VALUE io = rb_io_check_io(file);
if (NIL_P(io)) {
Expand Down
2 changes: 2 additions & 0 deletions spec/macruby/library/socket/sendfile_spec.rb
Expand Up @@ -49,6 +49,8 @@
lambda{ client.sendfile(Object.new, 0, 1) }.should raise_error(TypeError)
lambda{ client.sendfile(path, Object.new, 1) }.should raise_error(TypeError)
lambda{ client.sendfile(path, 0, Object.new) }.should raise_error(TypeError)
lambda{ client.sendfile(path, -1, 1) }.should raise_error(ArgumentError)
lambda{ client.sendfile(path, 0, -1) }.should raise_error(ArgumentError)
client.close
end

Expand Down

0 comments on commit 32b6ef3

Please sign in to comment.