Skip to content

Commit

Permalink
Report errors from get/setsockopt properly
Browse files Browse the repository at this point in the history
strerror(-1) is not valid, and the error may not be EINVAL.
  • Loading branch information
headius committed Oct 8, 2024
1 parent 4765ec9 commit a84bc99
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public IRubyObject getsockopt(ThreadContext context, IRubyObject _level, IRubyOb
int ret = SOCKOPT.getsockopt(fd.realFileno, intLevel, intOpt, buf, len);

if (ret != 0) {
throw runtime.newErrnoEINVALError(SOCKOPT.strerror(ret));
throw runtime.newErrnoFromLastPOSIXErrno();
}
flipBuffer(buf);
ByteList bytes = new ByteList(buf.array(), buf.position(), len.getValue());
Expand Down Expand Up @@ -535,7 +535,7 @@ public IRubyObject setsockopt(ThreadContext context, IRubyObject _level, IRubyOb
int ret = SOCKOPT.setsockopt(fd.realFileno, intLevel, intOpt, buf, buf.remaining());

if (ret != 0) {
throw runtime.newErrnoEINVALError(SOCKOPT.strerror(ret));
throw runtime.newErrnoFromLastPOSIXErrno();
}
}

Expand Down

0 comments on commit a84bc99

Please sign in to comment.