Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial implementation of sendto syscall #1791

Merged
merged 2 commits into from
Aug 27, 2020
Merged
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
62 changes: 55 additions & 7 deletions manticore/platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@
from ..exceptions import SolverError
from ..native.cpu.abstractcpu import Cpu, Syscall, ConcretizeArgument, Interruption
from ..native.cpu.cpufactory import CpuFactory
from ..native.memory import SMemory32, SMemory64, Memory32, Memory64, LazySMemory32, LazySMemory64
from ..native.memory import (
SMemory32,
SMemory64,
Memory32,
Memory64,
LazySMemory32,
LazySMemory64,
InvalidMemoryAccess,
)
from ..native.state import State
from ..platforms.platform import Platform, SyscallNotImplemented, unimplemented

Expand Down Expand Up @@ -2563,18 +2571,58 @@ def sys_recvfrom(

return len(data)

def sys_send(self, sockfd, buf, count, flags) -> int:
def sys_send(
self, sockfd: int, buf: int, count: int, flags: int, trace_str: str = "_send"
) -> int:
"""
send(2) is currently a nop; we don't communicate yet: The data is read
from memory, but not actually sent anywhere - we just return count to
pretend that it was.
"""
# Act like sys_sendto with zeroed dest_addr and addrlen
return self.sys_sendto(sockfd, buf, count, flags, 0, 0, trace_str=trace_str)

def sys_sendto(
self,
sockfd: int,
buf: int,
count: int,
flags: int,
dest_addr: int,
addrlen: int,
trace_str: str = "_sendto",
):
"""
sendto(2) is currently a nop; we don't communicate yet: The data is read
from memory, but not actually sent anywhere - we just return count to
pretend that it was.

Additionally, dest_addr and addrlen are dropped, so it behaves exactly
the same as send.
"""
# TODO: Do something with destination address. Could be used to better
# follow where data is being sent
if dest_addr != 0:
logger.warning("sys_sendto: Unimplemented non-NULL dest_addr")

if addrlen != 0:
logger.warning("sys_sendto: Unimplemented non-NULL addrlen")

try:
sock = self.fd_table.get_fdlike(sockfd)
except FdError as e:
return -e.err
except FdError:
return -errno.EBADF

if not isinstance(sock, Socket):
return -errno.ENOTSOCK

data = self.current.read_bytes(buf, count)
# XXX(yan): send(2) is currently a nop; we don't communicate yet
self.syscall_trace.append(("_send", sockfd, data))
try:
data = self.current.read_bytes(buf, count)
except InvalidMemoryAccess:
logger.info("SEND: buf within invalid memory. Returning EFAULT")
return -errno.EFAULT

self.syscall_trace.append((trace_str, sockfd, data))

return count

Expand Down