From 3656c95ecac83da108ad04084730dc283b681aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 26 Feb 2024 22:22:35 +0100 Subject: [PATCH] Ensure commands executed via FIFO are valid UTF-8 --- src/engine/shared/fifo.cpp | 22 ++++++++++++++++------ src/engine/shared/fifo.h | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/engine/shared/fifo.cpp b/src/engine/shared/fifo.cpp index 9af990a99..2595d8886 100644 --- a/src/engine/shared/fifo.cpp +++ b/src/engine/shared/fifo.cpp @@ -9,7 +9,7 @@ #include #include -void CFifo::Init(IConsole *pConsole, char *pFifoFile, int Flag) +void CFifo::Init(IConsole *pConsole, const char *pFifoFile, int Flag) { m_File = -1; @@ -70,18 +70,23 @@ void CFifo::Update() if(aBuf[i] != '\n') continue; aBuf[i] = '\0'; - m_pConsole->ExecuteLineFlag(pCur, m_Flag, -1); + if(str_utf8_check(pCur)) + { + m_pConsole->ExecuteLineFlag(pCur, m_Flag, -1); + } pCur = aBuf + i + 1; } - if(pCur < aBuf + Length) // missed the last line + if(pCur < aBuf + Length && str_utf8_check(pCur)) // missed the last line + { m_pConsole->ExecuteLineFlag(pCur, m_Flag, -1); + } } #elif defined(CONF_FAMILY_WINDOWS) #include -void CFifo::Init(IConsole *pConsole, char *pFifoFile, int Flag) +void CFifo::Init(IConsole *pConsole, const char *pFifoFile, int Flag) { m_pConsole = pConsole; if(pFifoFile[0] == '\0') @@ -187,11 +192,16 @@ void CFifo::Update() if(pBuf[i] != '\n') continue; pBuf[i] = '\0'; - m_pConsole->ExecuteLineFlag(pCur, m_Flag, -1); + if(str_utf8_check(pCur)) + { + m_pConsole->ExecuteLineFlag(pCur, m_Flag, -1); + } pCur = pBuf + i + 1; } - if(pCur < pBuf + Length) // missed the last line + if(pCur < pBuf + Length && str_utf8_check(pCur)) // missed the last line + { m_pConsole->ExecuteLineFlag(pCur, m_Flag, -1); + } free(pBuf); } diff --git a/src/engine/shared/fifo.h b/src/engine/shared/fifo.h index ad431b9bb..910b87e91 100644 --- a/src/engine/shared/fifo.h +++ b/src/engine/shared/fifo.h @@ -16,7 +16,7 @@ class CFifo #endif public: - void Init(IConsole *pConsole, char *pFifoFile, int Flag); + void Init(IConsole *pConsole, const char *pFifoFile, int Flag); void Update(); void Shutdown(); };