1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

UsespaceEmulator: Fix minor bugs in recvfrom() interception

* Pass the correct source address for copying tine addr_length.
  Previously, this was broken when addr_length was non-nullptr.

* Copy min(sizeof(address), address_length) bytes into address,
  instead of sizeof(address), which might be larger than the
  user buffer.

* Use sockaddr_storage instead of sockaddr_un. In practice they're
  both the same size, but this is what sockaddr_storage is for.

With this (in particular, the first fix), `ue /bin/ntpquery`
actually gets past the recvfrom() call :^)
This commit is contained in:
Nico Weber 2020-09-15 15:44:53 -04:00 committed by Andreas Kling
parent f0018aca1d
commit 62f615f0f4

View file

@ -599,13 +599,16 @@ int Emulator::virt$recvfrom(FlatPtr params_addr)
mmu().copy_from_vm(&params, params_addr, sizeof(params));
auto buffer = ByteBuffer::create_uninitialized(params.buffer.size);
sockaddr_un address;
if (params.addr)
mmu().copy_from_vm(&address, (FlatPtr)params.addr, sizeof(address));
if (!params.addr_length && params.addr)
return -EINVAL;
socklen_t address_length = 0;
if (params.addr_length)
mmu().copy_from_vm(&address_length, (FlatPtr)address_length, sizeof(address_length));
mmu().copy_from_vm(&address_length, (FlatPtr)params.addr_length, sizeof(address_length));
sockaddr_storage address;
if (params.addr)
mmu().copy_from_vm(&address, (FlatPtr)params.addr, min(sizeof(address), (size_t)address_length));
int rc = recvfrom(params.sockfd, buffer.data(), buffer.size(), params.flags, params.addr ? (struct sockaddr*)&address : nullptr, params.addr_length ? &address_length : nullptr);
if (rc < 0)