From a0f90f7c98830bd826d74e7e5c4d926c1683dfa6 Mon Sep 17 00:00:00 2001 From: snake-4 <18491360+snake-4@users.noreply.github.com> Date: Mon, 21 Apr 2025 03:29:00 +0200 Subject: [PATCH] Fixed stack overflow in CharPointer::operator= --- src/qt/qt_platform.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 26682528d..be40452fd 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -87,13 +87,13 @@ public: CharPointer &operator=(const QByteArray &ba) { if (s > 0) { + // If the size is known, copy up to s - 1 bytes + // and null-terminate the string. strncpy(b, ba.data(), s - 1); - b[s] = 0; - } else { - // if we haven't been told the length of b, just assume enough - // because we didn't get it from emulator code + b[s - 1] = 0; + } else if (ba.size() > 0) { + // If the size is unknown, copy the whole QByteArray strcpy(b, ba.data()); - b[ba.size()] = 0; } return *this; }