You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2022/04/27 12:35:41 UTC

[commons-daemon] branch master updated: Fix DAEMON-442 - Increase limit on log message size from 1024 to 4096

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git


The following commit(s) were added to refs/heads/master by this push:
     new 9d3cff5  Fix DAEMON-442 - Increase limit on log message size from 1024 to 4096
9d3cff5 is described below

commit 9d3cff50eb44b50e552413e86c63b8b2b0dbfdb4
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Apr 27 13:35:35 2022 +0100

    Fix DAEMON-442 - Increase limit on log message size from 1024 to 4096
    
    wsprintfW is limited to a buffer of size 1024. The switch to the newer
    functions allows (much) larger buffers to be used. 4096 seems like a
    reasonable limit.
---
 src/changes/changes.xml          |  4 ++++
 src/native/windows/include/log.h |  2 ++
 src/native/windows/src/log.c     | 49 +++++++++++++++++++++++++---------------
 src/site/xdoc/procrun.xml        |  6 +++--
 4 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d6f4ae3..f7cb738 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,10 @@
         path, explicitly state when default values are being used rather than
         logging blank values.
       </action>
+      <action issue="DAEMON-442" type="fix" dev="markt">
+        Procrun. Increase the size limit on the message component of log entries
+        to 4096 characters.
+      </action>
       <!-- UPDATES -->
       <action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">
         Bump actions/cache from 2.1.7 to 3.0.2 #41.
diff --git a/src/native/windows/include/log.h b/src/native/windows/include/log.h
index 5a6ad7d..c98b5aa 100644
--- a/src/native/windows/include/log.h
+++ b/src/native/windows/include/log.h
@@ -25,6 +25,8 @@ __APXBEGIN_DECLS
 
 static LPCWSTR  LOG_PATH_DEFAULT    = L"\\LogFiles\\Apache";
 
+#define LOG_MSG_MAX_LEN 4096
+
 #define APX_LOGLOCK(file)                           \
     APXMACRO_BEGIN                                  \
         DWORD _lmax = 0;                            \
diff --git a/src/native/windows/src/log.c b/src/native/windows/src/log.c
index cdf0e57..d2fece4 100644
--- a/src/native/windows/src/log.c
+++ b/src/native/windows/src/log.c
@@ -17,6 +17,7 @@
 #include "apxwin.h"
 #include "private.h"
 #include <stdio.h>
+#include <strsafe.h>
 
 #define LINE_SEP    "\r\n"
 #define LOGF_EXT    L".%04d-%02d-%02d.log"
@@ -64,7 +65,9 @@ static void logRotate(apx_logfile_st *lf, LPSYSTEMTIME t)
     /* Rotate time */
     lf->sysTime = *t;
     if (lf->dwRotate < 86400)
-        wsprintfW(sName, L"\\%s"  LOGF_EXR,
+        StringCchPrintf(sName,
+                  SIZ_PATHLEN,
+                  L"\\%s"  LOGF_EXR,
                   lf->szPrefix,
                   lf->sysTime.wYear,
                   lf->sysTime.wMonth,
@@ -73,7 +76,9 @@ static void logRotate(apx_logfile_st *lf, LPSYSTEMTIME t)
                   lf->sysTime.wMinute,
                   lf->sysTime.wSecond);
     else
-        wsprintfW(sName, L"\\%s"  LOGF_EXT,
+        StringCchPrintf(sName,
+                  SIZ_PATHLEN,
+                  L"\\%s"  LOGF_EXT,
                   lf->szPrefix,
                   lf->sysTime.wYear,
                   lf->sysTime.wMonth,
@@ -126,7 +131,8 @@ LPWSTR apxLogFile(
         szName   = L"";
     if (bTimeStamp) {
         if (dwRotate != 0 && dwRotate < 86400)
-            wsprintfW(sName,
+            StringCchPrintf(sName,
+                  SIZ_PATHLEN,
                   L"\\%s%s" LOGF_EXR,
                   szPrefix,
                   szName,
@@ -137,7 +143,8 @@ LPWSTR apxLogFile(
                   0,
                   0);
         else
-            wsprintfW(sName,
+            StringCchPrintf(sName,
+                      SIZ_PATHLEN,
                       L"\\%s%s" LOGF_EXT,
                       szPrefix,
                       szName,
@@ -146,7 +153,8 @@ LPWSTR apxLogFile(
                       sysTime.wDay);
     }
     else {
-        wsprintfW(sName,
+        StringCchPrintf(sName,
+                  SIZ_PATHLEN,
                   L"\\%s%s",
                   szPrefix,
                   szName);
@@ -202,7 +210,9 @@ HANDLE apxLogOpen(
     if (!szPrefix)
         szPrefix = L"commons-daemon";
     if (dwRotate != 0 && dwRotate < 86400)
-        wsprintfW(sName, L"\\%s"  LOGF_EXR,
+        StringCchPrintf(sName,
+                  SIZ_PATHLEN,
+                  L"\\%s"  LOGF_EXR,
                   szPrefix,
                   sysTime.wYear,
                   sysTime.wMonth,
@@ -211,7 +221,9 @@ HANDLE apxLogOpen(
                   0,
                   0);
     else
-        wsprintfW(sName, L"\\%s"  LOGF_EXT,
+        StringCchPrintf(sName,
+                  SIZ_PATHLEN,
+                  L"\\%s"  LOGF_EXT,
                   szPrefix,
                   sysTime.wYear,
                   sysTime.wMonth,
@@ -318,7 +330,7 @@ apxLogWrite(
     ...)
 {
     va_list args;
-    CHAR    buffer[1024+32] = "";
+    CHAR    buffer[LOG_MSG_MAX_LEN] = "";
     LPSTR   szBp;
     int     len = 0;
     LPCSTR  file = szFile;
@@ -354,10 +366,10 @@ apxLogWrite(
     szBp = buffer;
     if (!szFormat) {
         if (dwMessageId == 0) {
-            lstrcpyA(szBp, "Unknown error code");
+            StringCchCopyA(szBp, LOG_MSG_MAX_LEN, "Unknown error code");
             if (dwLevel == APXLOG_LEVEL_ERROR) {
                 szBp += 18;
-                wsprintfA(szBp, " occured in (%s:%d) ", file, dwLine);
+                StringCchPrintfA(szBp, LOG_MSG_MAX_LEN -18, " occurred in (%s:%d) ", file, dwLine);
             }
         }
         else
@@ -365,7 +377,7 @@ apxLogWrite(
     }
     else {
         va_start(args, szFormat);
-        wvsprintfA(szBp, szFormat, args);
+        StringCchVPrintfA(szBp, LOG_MSG_MAX_LEN, szFormat, args);
         va_end(args);
     }
     len = lstrlenA(buffer);
@@ -385,7 +397,8 @@ apxLogWrite(
                 logRotate(lf, &t);
             }
             if (bTimeStamp) {
-                wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ",
+                StringCchPrintfA(sb, SIZ_PATHLEN,
+                          "[%d-%02d-%02d %02d:%02d:%02d] ",
                           t.wYear, t.wMonth, t.wDay,
                           t.wHour, t.wMinute, t.wSecond);
                 WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
@@ -395,17 +408,17 @@ apxLogWrite(
 
             if (szFunction && lf->dwLogLevel <= APXLOG_LEVEL_TRACE) {
                 /* add function name in TRACE mode. */
-                wsprintfA(sb, "(%10s:%-4d:%-27s) ", file, dwLine, szFunction);
+                StringCchPrintfA(sb, SIZ_PATHLEN, "(%10s:%-4d:%-27s) ", file, dwLine, szFunction);
                 WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
             } else if (file && lf->dwLogLevel <= APXLOG_LEVEL_DEBUG) {
                 /* add file and line in DEBUG mode. */
-                wsprintfA(sb, "(%10s:%-4d) ", file, dwLine);
+                StringCchPrintfA(sb, SIZ_PATHLEN, "(%10s:%-4d) ", file, dwLine);
                 WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
             }
 
 
             /* add thread ID to log output */
-            wsprintfA(sb, "[%5d] ", GetCurrentThreadId());
+            StringCchPrintfA(sb, SIZ_PATHLEN, "[%5d] ", GetCurrentThreadId());
             WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
 
             if (len)
@@ -491,12 +504,12 @@ apxDisplayError(
     }
     if (szFormat) {
         va_start(args, szFormat);
-        wvsprintfA(buffer, szFormat, args);
+        StringCchVPrintfA(buffer, SIZ_HUGLEN, szFormat, args);
         va_end(args);
         if (f && *f) {
             CHAR sb[SIZ_PATHLEN];
-            wsprintfA(sb, "%s (%d)", f, dwLine);
-            lstrcatA(sysbuf, sb);
+            StringCchPrintfA(sb, SIZ_PATHLEN, "%s (%d)", f, dwLine);
+            StringCchCatA(sysbuf, SIZ_HUGLEN, sb);
         }
         lstrlcatA(sysbuf, SIZ_HUGLEN, LINE_SEP);
         lstrlcatA(sysbuf, SIZ_HUGLEN, buffer);
diff --git a/src/site/xdoc/procrun.xml b/src/site/xdoc/procrun.xml
index 2351455..e126241 100644
--- a/src/site/xdoc/procrun.xml
+++ b/src/site/xdoc/procrun.xml
@@ -545,8 +545,10 @@ will add the new value(s) to any existing value(s).
     <tr>
     <td>--LogLevel</td>
     <td>Info</td>
-    <td>Defines the logging level and can be either <b>Error</b>,
-        <b>Info</b>, <b>Warn</b>, <b>Debug</b>, or <b>Trace</b>. (Case insensitive).
+    <td>Defines the logging level and can be either <b>Error</b>, <b>Warn</b>
+        <b>Info</b>, <b>Debug</b>, or <b>Trace</b>. (Case insensitive). Note
+        that for all log entires, the maximum length of the message component of
+        the log entry is 4096 characters.
     </td>
     </tr>
     <tr>