Skip to content

[Memory error/Bad free] Objects/setobject.c, PyMem_Free may free local variable. Found by Clang Static Analyzer(CSA) #123722

@wr-web

Description

@wr-web

Bug report

Bug description:

Objects/setobject.c
small_copy is a local variable

    setentry small_copy[PySet_MINSIZE];

In some situation, small_copy will be passed to oldtable

            /* We're not going to resize it, but rebuild the
               table anyway to purge old dummy entries.
               Subtle:  This is *necessary* if fill==size,
               as set_lookkey needs at least one virgin slot to
               terminate failing searches.  If fill < size, it's
               merely desirable, as dummies slow searches. */
            assert(so->fill > so->used);
            memcpy(small_copy, oldtable, sizeof(small_copy));
            oldtable = small_copy;

oldtable may be badly freed

    if (is_oldtable_malloced)
        PyMem_Free(oldtable);
    return 0;

More concrete report packed in report.zip.
File list:

  • report-316784.html
  • scanview.css
  • sorttable.js

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions