OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_channel.c versions 1.32 and 1.33
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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;

CVSTrac 2.0.1