DVReflectors icon indicating copy to clipboard operation
DVReflectors copied to clipboard

vsnprintf buffer overflow in YSFReflector

Open csylvain opened this issue 1 year ago • 1 comments

in Log.cpp, there is a 501 char buffer. the timestamp for log entries is about 27 chars. the std::vsnprintf which adds a log entry has a char limit of 500 chars.

500+27 > 501 and YSFReflector exits with SIGABRT before finishing the startup.

code was working with Ubuntu 22.04. it seems Ubuntu 24.04 is more strict about buffer limit checking.

Fix is:

diff --git a/YSFReflector/Log.cpp b/YSFReflector/Log.cpp
index 752601e..4a34c05 100644
--- a/YSFReflector/Log.cpp
+++ b/YSFReflector/Log.cpp
@@ -78,10 +78,12 @@ static bool logOpenRotate()

 #if !defined(_WIN32) && !defined(_WIN64)
                if (m_daemon)
-                       dup2(fileno(m_fpLog), fileno(stderr));
+//                     dup2(fileno(m_fpLog), fileno(stderr));
+                       // proper way? no magic numbers. not from the file pointer, stderr, either
+                       dup2(fileno(m_fpLog), STDERR_FILENO);
 #endif
        }
-
+
        m_tm = *tm;

        return status;
@@ -149,7 +151,8 @@ void Log(unsigned int level, const char* fmt, ...)
 {
        assert(fmt != NULL);

-       char buffer[501U];
+//     char buffer[501U];
+       char buffer[540U]; // need buffer space for max 500 *PLUS* the time string
 #if defined(_WIN32) || defined(_WIN64)
        SYSTEMTIME st;
        ::GetSystemTime(&st);

csylvain avatar Oct 16 '24 23:10 csylvain

Create a PR and I will merge it.

nostar avatar Oct 17 '24 15:10 nostar