Skip to content

Commit

Permalink
Fix serious reference counting issue in nb_error.h
Browse files Browse the repository at this point in the history
This is a quite serious error affecting nanobind on Python versions 3.11
and earlier. The ``python_error::traceback()`` incorrectly stole a
reference, likely causing undefined behavior via use-after-free. This
function was called as part of ``python_error::what()``, which is a
frequently used routine that generates a readable error message +
backtrace on the C++ side.
  • Loading branch information
wjakob committed Aug 23, 2023
1 parent c09f373 commit 30d30ca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/nanobind/nb_error.h
Expand Up @@ -65,7 +65,7 @@ class NB_EXPORT python_error : public std::exception {

#if PY_VERSION_HEX < 0x030C0000
handle type() const { return m_type; }
object traceback() const { return steal(m_traceback); }
object traceback() const { return borrow(m_traceback); }
#else
handle type() const { return value().type(); }
object traceback() const { return steal(PyException_GetTraceback(m_value)); }
Expand Down

0 comments on commit 30d30ca

Please sign in to comment.