Skip to content

Move m_pClass NULL check before dereference #135339

Closed

Description

@mopanasyk

Description

Potential Problem

In /src/coreclr/debug/di/rstype.cpp within the function CordbType::GetStaticFieldValue():

Line 51: dereference of pointer m_pClass. https://github.com/dotnet/runtime/blob/main/src/coreclr/debug/di/rstype.cpp#L51
Line 53: comparison of a pointer with NULL. https://github.com/dotnet/runtime/blob/main/src/coreclr/debug/di/rstype.cpp#L53

If m_pClass == NULL, dereferencing it in m_pClass->GetModule() would already crash. Checking for m_pClass == NULL after the dereference is redundant.

Possible Solution

The check m_pClass == NULL must be moved before the dereference:

    if (((m_elementType != ELEMENT_TYPE_CLASS) && (m_elementType != ELEMENT_TYPE_VALUETYPE)) || (m_pClass == NULL))
    {
        ThrowHR(E_INVALIDARG);
    }

    pImport = m_pClass->GetModule()->GetMetaDataImporter();

First, the check is performed, then the dereference.

Found by Linux Verification Center (portal.linuxtesting.ru (https://portal.linuxtesting.ru/) with SVACE.

Author M. Opanasyuk.

Reproduction Steps

Expected behavior

Actual behavior

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Oct 7, 2026
  2. dotnet-policy-service commented on Oct 7, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
    See info in area-owners.md if you want to be subscribed.

  3. removed
    untriaged
    on Oct 7, 2026
  4. locked and limited conversation to collaborators on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions