fixes #291 for incorrect syscall returns and some indent issues (#292)

* fixes #291 for incorrect syscall returns and some indent issues

* relative import fix

* commented weakref removal
This commit is contained in:
Theofilos Petsios 2017-06-08 17:39:39 -04:00 committed by GitHub
parent 776f6125ad
commit 584206f3f7

View File

@ -1,21 +1,22 @@
import fcntl
import cgcrandom
import weakref
import errno
import os, struct
import fcntl
import logging
import os
import random
import struct
from elftools.elf.elffile import ELFFile
from ..utils.helpers import issymbolic
from ..core.cpu.abstractcpu import Interruption, Syscall, ConcretizeArgument
from ..core.cpu.cpufactory import CpuFactory
from ..core.memory import SMemory32, SMemory64, Memory32, Memory64
from ..core.smtlib import Operators, ConstraintSet
from ..platforms.platform import Platform
from elftools.elf.elffile import ELFFile
import logging
import random
from ..core.cpu.arm import *
from ..core.executor import SyscallNotImplemented, ProcessExit
from . import linux_syscalls
logger = logging.getLogger("PLATFORM")
@ -98,7 +99,6 @@ class SymbolicFile(object):
path = File(path, mode)
assert isinstance(path, File)
#self._constraints = weakref.ref(constraints)
WILDCARD = '+'
symbols_cnt = 0
@ -622,7 +622,8 @@ class Linux(Platform):
#The "secure execution" mode of secure_getenv() is controlled by the
#AT_SECURE flag contained in the auxiliary vector passed from the
#kernel to user space.
auxvnames = {'AT_IGNORE': 1, # Entry should be ignored
auxvnames = {
'AT_IGNORE': 1, # Entry should be ignored
'AT_EXECFD': 2, # File descriptor of program
'AT_PHDR': 3, # Program headers for program
'AT_PHENT':4, # Size of program header entry
@ -998,11 +999,11 @@ class Linux(Platform):
'''
if not self._is_open(fd):
logger.info("LSEEK: Not valid file descriptor on lseek. Returning EBADF")
return errno.EBADF
return -errno.EBADF
if isinstance(self.files[fd], Socket):
logger.info("LSEEK: Not valid file descriptor on lseek. Fd not seekable. Returning EBADF")
return errno.EBADF
return -errno.EBADF
# Read the data and put in tin memory
self.files[fd].seek(offset)
@ -1016,12 +1017,12 @@ class Linux(Platform):
if count != 0:
if not self._is_open(fd):
logger.info("READ: Not valid file descriptor on read. Returning EBADF")
return errno.EBADF
return -errno.EBADF
# TODO check count bytes from buf
if not buf in self.current.memory: # or not self.current.memory.isValid(buf+count):
logger.info("READ: buf points to invalid address. Returning EFAULT")
return errno.EFAULT
return -errno.EFAULT
if isinstance(self.files[fd],Socket) and self.files[fd].is_empty():
return 0
@ -2041,7 +2042,7 @@ class DecreeEmu(object):
@staticmethod
def cgc_random(platform, buf, count, rnd_bytes):
import cgcrandom
from . import cgcrandom
if issymbolic(buf):
logger.info("Ask to write random bytes to a symbolic buffer")
raise ConcretizeArgument(0)