Sitelet https://web.archive.org/web/20250610102216/https://github.com/python/cpython/issues/100173
Skip to content

crash in embed mode(3.8.10) #100173

Closed as not planned
Closed as not planned
@mccoysc

Description

@mccoysc

Crash report

in a nodejs c++ addon's init function,i do init as the following code:


Py_InitializeEx(0);
PyEval_InitThreads();
Py_DECREF(PyImport_ImportModule("threading"));
m_state = PyEval_SaveThread();

and i export an interface to allow user import python module from js,

//before call "import",i have hold the GIL lock already in caller function.
CPyObject import(const std::string &modulename)
{
    auto name = modulename;
    auto pos = name.find_last_of("\\");
    if (pos == std::string::npos)
        pos = name.find_last_of("/");

    if (pos != std::string::npos)
    {
        auto dir = name.substr(0, pos);
        name = name.substr(pos + 1);
        auto sysPath = PySys_GetObject((char *)"path");
        CPyObject dirName = PyUnicode_FromString(dir.c_str());
        PyList_Insert(sysPath, 0, *dirName);
    }

    auto len = name.length();
    if (len > 2 && name[len - 3] == '.' && name[len - 2] == 'p' && name[len - 1] == 'y')
        name = name.substr(0, len - 3);

    PyErr_Clear();
    return pyModule = PyImport_ImportModule(name.c_str());

}

the above code PySys_GetObject((char *)"path") would make program crash.

Error messages

"access 0 memory address for..."

Your environment

gramine-sgx (image from docker hub with version v1.3.1)

  • CPython versions tested on:3.8.10 x64
  • Operating system and architecture:

gramine-sgx (docker image from docker hub with version v1.3.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.8 (EOL)end of lifetype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions