Skip to content

Сhecking for NULL #92566

Closed
Closed

Description

@VoroninArtemii

Description

We have two pointer pMT dereferences:

GetModule()->GetAssembly()->ThrowTypeLoadException(pInternalImport, pMT->GetCl(), IDS_CLASSLOAD_BADFORMAT);

GetModule()->GetAssembly()->ThrowTypeLoadException(pInternalImport, pMT->GetCl(), IDS_CLASSLOAD_BADFORMAT);

And they are absolutely identical. But before the second dereference there is a check for NULL, before the first there is not. I assume two options. The first option is an unnecessary check. The second option is that the pointer at the first dereference can really be NULL. Between these two dereferences, the pointer pMT itself does not change. Only the following lines:
_ASSERTE(tkParam == GetToken());
TypeHandle thConstraint = ClassLoader::LoadTypeDefOrRefOrSpecThrowing(GetModule(), tkConstraintType,
&typeContext,
ClassLoader::ThrowIfNotFound,
ClassLoader::FailIfUninstDefOrRef,
ClassLoader::LoadTypes,
level);
constraints[i++] = thConstraint;

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

Author A. Voronin.

Activity

  1. ghost added
    needs-area-label
    on Sep 24, 2023
  2. ghost added
    untriaged
    on Sep 24, 2023
  3. added and removed
    needs-area-label
    on Sep 24, 2023
  4. self-assigned this
    on Sep 28, 2023
  5. added this to the 9.0.0 milestone on Sep 28, 2023
  6. ghost removed
    untriaged
    on Sep 28, 2023
  7. steveisok commented on Jul 25, 2024

    @steveisok
    Member

    Not 100% sure, but a good explanation may be the first dereference never gets hit when taking the else path in:

    else
    {
    _ASSERTE(TypeFromToken(defToken) == mdtTypeDef);
    bool foundResult = false;
    if (!GetModule()->m_pTypeGenericInfoMap->HasConstraints(defToken, &foundResult) && foundResult)
    {
    m_numConstraints = 0;
    return;
    }
    TypeHandle genericType = LoadOwnerType();
    _ASSERTE(genericType.IsGenericTypeDefinition());
    SigTypeContext::InitTypeContext(genericType,&typeContext);
    }

  8. added
    help wanted
    and removed
    help wanted
    on Jul 26, 2024
  9. lambdageek commented on Jul 26, 2024

    @lambdageek
    Member

    yea I think there's probably a situation where we come in from the "else" case that @steveisok mentioned (line 855) and then hit try to throw from line 888.

    But it would only happen with malformed IL, I think.

    There might be a valid issue here, but the majority of the work will be in crafting an appropriately malformed assembly for a test case.

    PRs welcome

  10. modified the milestones: 9.0.0, Future on Jul 26, 2024
  11. added
    in-pr
    on Nov 2, 2026
  12. added a commit that references this issue on Nov 3, 2026
    36797f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-TypeSystem-coreclrhelp wantedin-pr

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions