Skip to content

Code cleanup: inefficient/redundant code in ObjectSnap #5

@rprichard

Description

@rprichard
ObjectSnap::ObjectSnap() {
    if (!hasBuiltinCompareObjectHandles() && !needsWow64HandleLookup()) {
        m_table = queryNtHandles();
        m_hasTable = true;
    }
}

uint64_t ObjectSnap::object(RemoteHandle h) {
    if (needsWow64HandleLookup()) {
        return wow64LookupKernelObject(h.worker().pid(), h.value());
    }
    if (!m_hasTable) {
        m_table = queryNtHandles();
    }
    return reinterpret_cast<uint64_t>(ntHandlePointer(
        m_table, h.worker().pid(), h.value()));
}

This code looks suspicious to me. I think ObjectSnap::object could in principle initialize m_table multiple times. I think it should also set m_hasTable to true, and then the constructor can be removed.

ObjectSnap::object is public, so it could be invoked from a test case without going through eq. I thought that actually mattered, but now I don't see any call sites, so maybe it doesn't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions