osaf/libs/core/common/logtrace.c |  20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)


logtrace has locally defined limit of 1024 bytes for the length of message to 
be printed.
It is possible that user of logtrace (TRACE OR LOG_**) can pass messages longer 
than 1024 bytes.
But, logtrace() is not checking for the return value of vsnprintf. vsnprintf 
would return the number of bytes it
could have printed and not the actual bytes printed in scenarios when the 
length passed to vsnprintf is smaller
than the length of the string passed to vsnprintf.
The patch makes the effective max length of logtrace messages to 1023 and 
introduces a turncation
character T (like in the log service spec) whenever messages longer than 1023 
are passed to TRACE or LOG_**.

diff --git a/osaf/libs/core/common/logtrace.c b/osaf/libs/core/common/logtrace.c
--- a/osaf/libs/core/common/logtrace.c
+++ b/osaf/libs/core/common/logtrace.c
@@ -104,11 +104,21 @@ static void output(const char *file, uns
                getpid(), file, line, prefix_name[priority + category], format);
        i = vsnprintf(log_string, sizeof(log_string), preamble, ap);
 
-       /* Add line feed if not there already */
-       if (log_string[i - 1] != '\n') {
-               log_string[i] = '\n';
-               log_string[i + 1] = '\0';
-               i++;
+       /* Check if the logtrace user had passed message length >= logtrace 
array limit of 1024.
+        * If so, prepare/add space for line feed and truncation character 'T'.
+        */
+       if (i >= 1024) {
+               i = 1024;
+               log_string[i-2] = 'T';
+               log_string[i-1] = '\n';
+               log_string[i] = '\0';//
+       } else {
+               /* Add line feed if not there already */
+               if (log_string[i - 1] != '\n') {
+                       log_string[i] = '\n';
+                       log_string[i + 1] = '\0';
+                       i++;
+               }
        }
 
        /* If we got here without a file descriptor, trace was enabled in 
runtime, open the file */

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to