]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
buf_printf will now return false on errors, such as truncation
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Sat, 19 Jul 2008 03:39:59 +0000 (03:39 +0000)
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Sat, 19 Jul 2008 03:39:59 +0000 (03:39 +0000)
due to overflow.

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

buffer.c
buffer.h

index c90ff9f5055fe9b37b03b79a4933a6c3a4722210..498861ec96f1a17f448cf1d761c9cc65a0301862 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -182,9 +182,10 @@ buf_sub (struct buffer *buf, int size, bool prepend)
 /*
  * printf append to a buffer with overflow check
  */
-void
+bool
 buf_printf (struct buffer *buf, const char *format, ...)
 {
+  int ret = false;
   if (buf_defined (buf))
     {
       va_list arglist;
@@ -193,13 +194,17 @@ buf_printf (struct buffer *buf, const char *format, ...)
 
       if (cap > 0)
        {
+         int stat;
          va_start (arglist, format);
-         vsnprintf ((char *)ptr, cap, format, arglist);
+         stat = vsnprintf ((char *)ptr, cap, format, arglist);
          va_end (arglist);
          *(buf->data + buf->capacity - 1) = 0; /* windows vsnprintf needs this */
          buf->len += (int) strlen ((char *)ptr);
+         if (stat >= 0 && stat < cap)
+           ret = true;
        }
     }
+  return ret;
 }
 
 /*
index 8888869159e84cec71df413a4f5098a23306d2b0..7de3363dc472d5bf7e3036f30680a6c950c4dad3 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -206,7 +206,7 @@ has_digit (const unsigned char* src)
 /*
  * printf append to a buffer with overflow check
  */
-void buf_printf (struct buffer *buf, const char *format, ...)
+bool buf_printf (struct buffer *buf, const char *format, ...)
 #ifdef __GNUC__
     __attribute__ ((format (printf, 2, 3)))
 #endif