Merge pull request #4658 from milescoviello/fix/sockopt-option-lengths
fix(libkernel): accept socket option values longer than an int
This commit is contained in:
commit
3779597778
|
|
@ -596,7 +596,7 @@ int APS5_VABI setsockopt_nid_postfix(int descriptor, int level, int option,
|
|||
if (!socket) return -1;
|
||||
const int nativeOption = Option(option);
|
||||
if (level != 0xffff || nativeOption == -1) return Fail(42);
|
||||
if (!value || length != sizeof(int)) return Fail(22);
|
||||
if (!value || length < sizeof(int)) return Fail(22);
|
||||
return ::setsockopt(socket->value, SOL_SOCKET, nativeOption,
|
||||
static_cast<const char*>(value), sizeof(int)) ? Fail(NativeError()) : 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,12 @@ int main() {
|
|||
int option = 0;
|
||||
std::uint32_t optionSize = sizeof(option);
|
||||
Require(getsockopt_nid_postfix(sender, 0xffff, 0x20, &option, &optionSize) == 0 && option != 0);
|
||||
for (const std::int64_t wide : {0, 1}) {
|
||||
Require(setsockopt_nid_postfix(sender, 0xffff, 0x20, &wide, sizeof(wide)) == 0);
|
||||
optionSize = sizeof(option);
|
||||
Require(getsockopt_nid_postfix(sender, 0xffff, 0x20, &option, &optionSize) == 0 && (option != 0) == (wide != 0));
|
||||
}
|
||||
Require(setsockopt_nid_postfix(sender, 0xffff, 0x20, &enabled, 2) == -1 && *__error_nid_postfix() == 22);
|
||||
Require(setsockopt_nid_postfix(sender, 0xffff, 12345, &enabled, sizeof(enabled)) == -1);
|
||||
Require(*__error_nid_postfix() == 42);
|
||||
const int unconnected = socket_nid_postfix(2, 2, 0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue