Comments inline
/Hans

> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: den 12 september 2014 23:17
> To: Hans Feldt; [email protected]; [email protected]
> Cc: [email protected]
> Subject: [PATCH 1 of 1] base: check and truncate(with character T) logtrace 
> messages >= 1024 bytes [#970]
> 
>  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';
[Hans] write at 1022
> +             log_string[i-1] = '\n';
[Hans] write at 1023
> +             log_string[i] = '\0';//
[Hans] write at 1024 outside the buffer!
> +     } else {
[Hans] here i can be 1023
> +             /* Add line feed if not there already */
> +             if (log_string[i - 1] != '\n') {
> +                     log_string[i] = '\n';
[Hans] write at 1023
> +                     log_string[i + 1] = '\0';
[Hans] write at 1024 outside the buffer!
> +                     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