Commit c9cfb00a authored by Bernd Buschinski's avatar Bernd Buschinski Committed by Sven Brauch
Browse files

Fix possible crash in AstTransformer

This fixes the following crash for me (only in a very huge Python project)

```
Thread 28 "Queue(0x555559d" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff8133e6c0 (LWP 25746)]
Python::AstTransformer::getattr<int> (this=0x7fff8133c550,
attr=0x7fff9c2de165 "lineno", obj=Python Exception <class
'gdb.error'>: There is no member named ma_keys.
) at /var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.cpp:37
37      /var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.cpp:
No such file or directory.
(gdb) bt
#0  Python::AstTransformer::getattr<int>(_object*, char const*)
constPython Exception <class 'gdb.error'>: There is no member named
ma_keys.
 (this=0x7fff8133c550, attr=0x7fff9c2de165 "lineno", obj=) at
/var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.cpp:37
#1  Python::AstTransformer::visitAliasNode(_object*,
Python::Ast*)Python Exception <class 'gdb.error'>: There is no member
named ma_keys.
 (this=0x7fff8133c550, node=, parent=<optimized out>) at
/var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.cpp:194
#2  0x00007fff9c2db35e in
Python::AstTransformer::visitNodeList<Python::AliasAst>(_object*,
Python::Ast*)Python Exception <class 'gdb.error'>: There is no member
named ma_keys.
 (this=this@entry=0x7fff8133c550, node=node@entry=,
parent=parent@entry=0x7fff680142d0)
    at /var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.cpp:142
#3  0x00007fff9c2d7058 in
Python::AstTransformer::visitStmtNode(_object*, Python::Ast*)Python
Exception <class 'gdb.error'>: There is no member named ma_keys.
 (this=0x7fff8133c550, node=, parent=0x7fff6810ad50) at
/var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.cpp:1155
#4  0x00007fff9c2db40e in
Python::AstTransformer::visitNodeList<Python::Ast>(_object*,
Python::Ast*)Python Exception <class 'gdb.error'>: There is no member
named ma_keys.
 (this=this@entry=0x7fff8133c550, node=node@entry=,
parent=parent@entry=0x7fff6810ad50)
    at /var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.cpp:142
#5  0x00007fff9c2d78bf in
Python::AstTransformer::visitModuleNode(_object*, Python::Ast*)Python
Exception <class 'gdb.error'>: There is no member named ma_keys.
 (this=this@entry=0x7fff8133c550, node=node@entry=, parent=parent@entry=0x0)
    at /var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.cpp:128
#6  0x00007fff9c2d0b3f in Python::AstTransformer::run(_object*,
QString)Python Exception <class 'gdb.error'>: There is no member named
ma_keys.
 (moduleName=..., syntaxtree=, this=0x7fff8133c550) at
/var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/asttransformer.h:30
#7  Python::AstBuilder::parse(QUrl const&, QString&)
(this=this@entry=0x7fff8133c908, filename=..., contents=...) at
/var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/astbuilder.cpp:264
#8  0x00007fff9c2c0cce in Python::ParseSession::parse()
(this=0x7fff68002510) at
/var/tmp/portage/dev-util/kdevelop-python-9999/work/kdevelop-python-9999/parser/parsesession.cpp:65
#9  0x00007fff81ec0f94 in
Python::ParseJob::run(QSharedPointer<ThreadWeaver::JobInterface>,
ThreadWeaver::Thread*) (this=<optimized out>) at
/usr/include/qt5/QtCore/qshareddata.h:160
#10 0x00007ffff295d937 in
ThreadWeaver::IdDecorator::run(QSharedPointer<ThreadWeaver::JobInterface>,
ThreadWeaver::Thread*) () at /usr/lib64/libKF5ThreadWeaver.so.5
#11 0x00007ffff295d586 in
ThreadWeaver::Executor::run(QSharedPointer<ThreadWeaver::JobInterface>
const&, ThreadWeaver::Thread*) () at
/usr/lib64/libKF5ThreadWeaver.so.5
#12 0x00007ffff295e3ef in
ThreadWeaver::Job::execute(QSharedPointer<ThreadWeaver::JobInterface>
const&, ThreadWeaver::Thread*) () at
/usr/lib64/libKF5ThreadWeaver.so.5
#13 0x00007ffff2962651 in ThreadWeaver::Thread::run() () at
/usr/lib64/libKF5ThreadWeaver.so.5
#14 0x00007ffff62caea7 in  () at /usr/lib64/libQt5Core.so.5
#15 0x00007ffff60b2845 in start_thread (arg=<optimized out>) at
pthread_create.c:442
#16 0x00007ffff613236c in clone3 () at
../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) p v
$1 = 0x0
```

After enabling the additional qDebug in the Code, the last output was:
```
getattr<int>:  "<ast.Expr object at 0x7f446ff17310>" .
lineno v= "<NULL>"
```

And I currently have 3 python versions installed (gentoo)

- dev-lang/python-3.11.0_p2
- dev-lang/python-3.10.8_p3
- dev-lang/python-3.9.15_p3
parent 3dfcf4b3
Pipeline #274696 skipped
......@@ -33,8 +33,7 @@ int AstTransformer::getattr(PyObject *obj, const char *attr) const
int result;
PyObject *v = PyObject_GetAttrString(obj, attr);
// qDebug() << "getattr<int>: " << PyUnicodeObjectToQString(PyObject_Str(obj)) << "." << attr << "v=" << PyUnicodeObjectToQString(PyObject_Str(v));
Q_ASSERT(v); // attr missing
if (PyLong_Check(v)) {
if (v && PyLong_Check(v)) {
result = PyLong_AsLong(v);
} else {
result = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment