Hi,

If i == 1023, then you end up in "else" branch, and you have the same problem 
again (i + 1 == 1024)
+    } else {
+        /* Add line feed if not there already */
+        if (log_string[i - 1] != '\n') {
+            log_string[i] = '\n';
+            log_string[i + 1] = '\0';
+            i++;
+        }
      }

Best regards,
Zoran

-----Original Message-----
From: Neelakanta Reddy [mailto:[email protected]] 
Sent: den 12 september 2014 16:28
To: [email protected]; Hans Feldt; [email protected]
Cc: [email protected]
Subject: Re: [devel] [PATCH 1 of 1] base: check and truncate(with character T) 
logtrace messages >= 1024 bytes [#970]

Hi Mathi,

Following are my comments:

1. Build error

make[6]: Entering directory
`/home/staging/patches/imm/staging_970/osaf/libs/core/common'
if /bin/sh ../../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. 
-I. -I../../../.. 
-I../../../../osaf/libs/saf/include -I../../../../osaf/libs/core/include
-I../../../../osaf/libs/core/leap/include
-I../../../../osaf/libs/core/mds/include 
-I../../../../osaf/libs/core/common/include   -Wall -fno-strict-aliasing 
-Werror -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector 
-DINTERNAL_VERSION_ID='"5773:ecada8cb88a3"'  -g -O2 -MT 
libopensaf_common_la-logtrace.lo -MD -MP -MF 
".deps/libopensaf_common_la-logtrace.Tpo" -c -o 
libopensaf_common_la-logtrace.lo `test -f 'logtrace.c' || echo './'`logtrace.c; 
\
     then mv -f ".deps/libopensaf_common_la-logtrace.Tpo" 
".deps/libopensaf_common_la-logtrace.Plo"; else rm -f 
".deps/libopensaf_common_la-logtrace.Tpo"; exit 1; fi
  gcc -DHAVE_CONFIG_H -I. -I. -I../../../.. 
-I../../../../osaf/libs/saf/include -I../../../../osaf/libs/core/include
-I../../../../osaf/libs/core/leap/include
-I../../../../osaf/libs/core/mds/include
-I../../../../osaf/libs/core/common/include -Wall -fno-strict-aliasing -Werror 
-fPIC -D_FORTIFY_SOURCE=2 -fstack-protector 
-DINTERNAL_VERSION_ID=\"5773:ecada8cb88a3\" -g -O2 -MT 
libopensaf_common_la-logtrace.lo -MD -MP -MF 
.deps/libopensaf_common_la-logtrace.Tpo -c logtrace.c  -fPIC -DPIC -o 
.libs/libopensaf_common_la-logtrace.o
logtrace.c: In function 'output':
logtrace.c:114:13: error: array subscript is above array bounds 
[-Werror=array-bounds]
    log_string[i] = '\0';//
              ^
cc1: all warnings being treated as errors


2. to get rid of above error i changed the patch to

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 = 1023;
+        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 */


3. when exactly the i value is 1023 then i am seeing "\0" is printed in 
next line:


Sep 12 19:31:18.560259 osafimmnd [3052:ImmModel.cc:5313] T5 COMMITING 
CREATE of 
attr=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGT
^@Sep 12 19:31:18.560427 osafimmnd [3052:ImmModel.cc:5376] NO Ccb 4 
COMMITTED (immcfg_Slot-5_3512)

4. Again i changed the patch as below and i did not see any extra 
character in the nextline of trace
+       if (i >= 1023) {
+        i = 1023;
+        log_string[i-2] = 'T';
+        log_string[i-1] = '\n';
+        log_string[i] = '\0';//
+    } else {


/Neel.


On Saturday 13 September 2014 02:46 AM, [email protected] wrote:
>   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

------------------------------------------------------------------------------
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