OSSP CVS Repository

ossp - Check-in [3668]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3668
Date: 2003-Nov-06 16:31:47 (local)
2003-Nov-06 15:31:47 (UTC)
User:thl
Branch:
Comment: fix PR#23: l2 does not terminate a message when it contains a newline
Tickets:
#23 Prefix channel buffer bug when '\n' character present
Inspections:
Files:
ossp-pkg/l2/ChangeLog      1.8 -> 1.9     7 inserted, 0 deleted
ossp-pkg/l2/TODO      1.61 -> 1.62     0 inserted, 7 deleted
ossp-pkg/l2/l2_channel.c      1.32 -> 1.33     15 inserted, 7 deleted
ossp-pkg/l2/l2_p.h      1.34 -> 1.35     4 inserted, 2 deleted

ossp-pkg/l2/ChangeLog 1.8 -> 1.9

--- ChangeLog    2003/11/06 11:59:02     1.8
+++ ChangeLog    2003/11/06 15:31:47     1.9
@@ -11,6 +11,13 @@
 
   Changes between 0.9.4 and 0.9.5 (25-Sep-2003 to ??-???-????)
 
+    *) Fix Problem where l2 does not terminate a message when it
+       contains a \n so if previous message was longer the part between
+       \n and the end of the previous message is repeated in the current
+       message.
+       http://cvs.ossp.org/tktview?tn=23
+       [Thomas Lotterer <thomas@lotterer.net>]
+
     *) Added bison-locations option to scanner, fixing the missing
        reentrant yylloc with flex-2.5.31.
        [Michael Schloh <michael@schloh.com>]


ossp-pkg/l2/TODO 1.61 -> 1.62

--- TODO 2003/11/06 12:58:21     1.61
+++ TODO 2003/11/06 15:31:47     1.62
@@ -10,13 +10,6 @@
   ====
 
 20030611 thl
-    Fix Problem where l2 does not terminate a message when
-    it contains a \n so if previous message was longer the
-    part between \n and the end of the previous message is
-    repeated in the current message.
-    http://cvs.ossp.org/tktview?tn=23
-
-20030611 thl
     Fix Problem where l2 is not thread safe when multiple
     threads use the same env as is true with with fsl.
     http://cvs.ossp.org/tktview?tn=24


ossp-pkg/l2/l2_channel.c 1.32 -> 1.33

--- l2_channel.c 2003/02/13 15:37:28     1.32
+++ l2_channel.c 2003/11/06 15:31:47     1.33
@@ -582,18 +582,26 @@
     vfmt.data[1].i  = L2_ERR_FMT;
     vfmt.flush  = l2_channel_vlog_flush;
     vfmt.format = l2_channel_vlog_format;
-    if ((len = l2_util_format(&vfmt, fmt, ap)) == -1)
+    len = l2_util_format(&vfmt, fmt, ap);
+
+    /* check for formatting error including buffer overrun */
+    if (len == -1)
         return (l2_result_t)(vfmt.data[1].i);
+
+    /* check for formatting led to completely empty message */
     if (len == 0)
         return L2_ERR_FMT;
 
-    /* make sure a trailing newline exists */
-    if (env->message[len-1] != '\n') {
-        if (len == L2_MAX_MSGSIZE)
-            return L2_ERR_MEM;
+    /* check for formatting led to newline-only message */
+    if (len == 1 && env->message[len] == '\n')
+        return L2_ERR_FMT;
+
+    /* make sure a trailing newline exists; L2_MSG_BUFSIZE has room for CR/LF */
+    if (env->message[len-1] != '\n')
         env->message[len++] = '\n';
-        env->message[len]   = '\0';
-    }
+
+    /* make sure a trailing NUL exists; L2_MSG_BUFSIZE has room for NUL  */
+    env->message[len] = '\0';
 
     /* write message to channel */
     rv = L2_OK;


ossp-pkg/l2/l2_p.h 1.34 -> 1.35

--- l2_p.h       2003/01/06 11:41:52     1.34
+++ l2_p.h       2003/11/06 15:31:47     1.35
@@ -73,7 +73,9 @@
         cu(value)
 
 /* some hard-coded sizes :-( */
-#define L2_MAX_MSGSIZE         4096
+#define L2_MAX_OUTSIZE          4098 /* this value is for compatiblity with previous versions of L2 */
+#define L2_MAX_MSGSIZE          L2_MAX_OUTSIZE - 2 /* leave room for CR/LF although OSSP/UNIX use LF only */
+#define L2_MSG_BUFSIZE          L2_MAX_OUTSIZE + 1 /* reserve space for convenient trailing NUL */
 #define L2_MAX_FORMATTERS       128
 #define L2_MAX_HANDLERS         128
 #define L2_BROKEN_TIMER          -1
@@ -112,7 +114,7 @@
     int                   interval;
     l2_formatter_entry_t  formatters[L2_MAX_FORMATTERS];
     l2_handler_t         *handlers[L2_MAX_HANDLERS];
-    char                  message[L2_MAX_MSGSIZE];
+    char                  message[L2_MSG_BUFSIZE];
     char                  szError[1024];
     char                  szErrorInfo[512];
     l2_result_t           rvErrorInfo;

CVSTrac 2.0.1