]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
status_printf function will now set error flag on
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Fri, 18 Jul 2008 07:15:27 +0000 (07:15 +0000)
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Fri, 18 Jul 2008 07:15:27 +0000 (07:15 +0000)
output truncation or failure of write() to write the
expected number of bytes.

Raised STATUS_PRINTF_MAXLEN to 512 (from 256).

git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@3077 e7ae566f-a301-0410-adde-c780ea21d3b5

init.c
status.c

diff --git a/init.c b/init.c
index 218fae1919f920c4b1c64dd8badb5cfcdcc6d134..61b23e3e45e9274eebff63384961c57600cb246b 100644 (file)
--- a/init.c
+++ b/init.c
@@ -439,7 +439,7 @@ init_static (void)
   return false;
 #endif
 
-#if 0
+#ifdef GEN_PATH_TEST
   {
     struct gc_arena gc = gc_new ();
     const char *fn = gen_path ("foo",
@@ -448,7 +448,20 @@ init_static (void)
     printf ("%s\n", fn);
     gc_free (&gc);
   }
+  return false;
+#endif
 
+#ifdef STATUS_PRINTF_TEST
+  {
+    struct gc_arena gc = gc_new ();
+    const char *tmp_file = create_temp_filename ("/tmp", "foo", &gc);
+    struct status_output *so = status_open (tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
+    status_printf (so, "%s", "foo");
+    status_printf (so, "%s", "bar");
+    if (!status_close (so))
+      msg (M_WARN, "STATUS_PRINTF_TEST: %s: write error", tmp_file);
+    gc_free (&gc);
+  }
   return false;
 #endif
 
index 2cf261112c71ef973a4d00c191ec3ac5b3a840e4..368f9a7cc30553141c7f81d47bec20426e10a03b 100644 (file)
--- a/status.c
+++ b/status.c
@@ -212,7 +212,7 @@ status_close (struct status_output *so)
   return ret;
 }
 
-#define STATUS_PRINTF_MAXLEN 256
+#define STATUS_PRINTF_MAXLEN 512
 
 void
 status_printf (struct status_output *so, const char *format, ...)
@@ -221,28 +221,32 @@ status_printf (struct status_output *so, const char *format, ...)
     {
       char buf[STATUS_PRINTF_MAXLEN+2]; /* leave extra bytes for CR, LF */
       va_list arglist;
+      int stat;
 
       va_start (arglist, format);
-      vsnprintf (buf, STATUS_PRINTF_MAXLEN, format, arglist);
+      stat = vsnprintf (buf, STATUS_PRINTF_MAXLEN, format, arglist);
       va_end (arglist);
       buf[STATUS_PRINTF_MAXLEN - 1] = 0;
 
-      if (so->msglevel >= 0)
+      if (stat < 0 || stat >= STATUS_PRINTF_MAXLEN)
+       so->errors = true;
+
+      if (so->msglevel >= 0 && !so->errors)
        msg (so->msglevel, "%s", buf);
 
-      if (so->fd >= 0)
+      if (so->fd >= 0 && !so->errors)
        {
          int len;
          strcat (buf, "\n");
          len = strlen (buf);
          if (len > 0)
            {
-             if (write (so->fd, buf, len) < 0)
+             if (write (so->fd, buf, len) != len)
                so->errors = true;
            }
        }
 
-      if (so->vout)
+      if (so->vout && !so->errors)
        {
          chomp (buf);
          (*so->vout->func) (so->vout->arg, so->vout->flags_default, buf);