Merge pull request #8070 from Robyt3/Engine-FIFO-UTF8-Check

Ensure commands executed via FIFO are valid UTF-8
This commit is contained in:
Dennis Felsing 2024-03-06 22:12:02 +00:00 committed by GitHub
commit 117ccd7adf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 7 deletions

View file

@ -9,7 +9,7 @@
#include <sys/types.h>
#include <unistd.h>
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 <windows.h>
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);
}

View file

@ -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();
};