Skip to content

posix ql_syscall_bind unpacks sin_family with wrong endianess on MIPS MSB #521

Description

@nezza

Describe the bug
Running OpenWRT's uhttpd (uhttpd: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mips-sf.so.1, no section header) the bind syscall will fail because sin_family is unpacked as little endian, even though it's encoded in big endian.

The example file is attached as uhttpd.zip.

Sample Code/Sample fix

def ql_syscall_bind(ql, bind_fd, bind_addr, bind_addrlen,  *args, **kw):
    regreturn = 0

    if ql.archtype== QL_ARCH.X8664:
        data = ql.mem.read(bind_addr, 8)
    else:
        data = ql.mem.read(bind_addr, bind_addrlen)

    # Works
    sin_family, = struct.unpack(">h", data[:2])
    # Doesn't work
    # sin_family, = struct.unpack("<h", data[:2])

I am unsure how to solve this, as I assume this works on other architectures? What's the "qiling way" of handling unpacks for different endianess?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions