Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2035?usp=email

to review the following change.


Change subject: buffer: add optional -fbounds-safety annotations
......................................................................

buffer: add optional -fbounds-safety annotations

Add Clang -fbounds-safety annotations to struct buffer and the buffer
API, and allow building buffer.c with -fbounds-safety via
--enable-fbounds-safety (autotools) or -DENABLE_FBOUNDS_SAFETY=ON
(CMake). The option is off by default.

Only buffer.c is built with the flag for now, since most other files and
some system and library headers are not annotated yet. CMake sets it as
a source file property, so it also applies to the unit tests that build
buffer.c. Automake builds buffer.c as a small convenience library with
its own CFLAGS.

compat.h uses <ptrcheck.h> when it is available, since some system
headers include it unconditionally, and only defines no-op fallbacks
for annotations that are still undefined.

The annotations used on non-static declarations (__sized_by,
__counted_by, __null_terminated, __unsafe_indexable) do not change the
representation of pointers, so buffer.o is ABI compatible with code
built without -fbounds-safety. The wide __bidi_indexable pointers are
only used as return types of static inline helpers.

The free function callback of gc_addspecial() takes a
void *__unsafe_indexable, which matches how the macOS SDK declares
free(), so free() can be passed without a cast.

Change-Id: Ib57d973a2f8ef48c3710f7d034da1a91c64d4755
Signed-off-by: Jeff Bindel <[email protected]>
---
M .clang-format
M CMakeLists.txt
M configure.ac
M src/compat/compat.h
M src/openvpn/Makefile.am
M src/openvpn/buffer.c
M src/openvpn/buffer.h
7 files changed, 163 insertions(+), 77 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/35/2035/1

diff --git a/.clang-format b/.clang-format
index 23d224b..312b6d3 100644
--- a/.clang-format
+++ b/.clang-format
@@ -17,6 +17,7 @@
 AllowShortFunctionsOnASingleLine: None
 AllowShortIfStatementsOnASingleLine: Never
 AllowShortLoopsOnASingleLine: false
+AttributeMacros: [__counted_by, __counted_by_or_null, __sized_by, 
__sized_by_or_null]
 BinPackArguments: true
 BinPackParameters: true
 BreakAfterReturnType: AllDefinitions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 184a95a..bd22587 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,6 +43,8 @@
 option(ENABLE_DEBUG "Enable building with debug" OFF)

 option(ENABLE_DNS_UPDOWN_BY_DEFAULT "Run --dns-updown hook by default" ON)
+
+option(ENABLE_FBOUNDS_SAFETY "Enable experimental Clang -fbounds-safety 
annotations (OFF by default)" OFF)
 set(DNS_UPDOWN_PATH "${CMAKE_INSTALL_PREFIX}/libexec/openvpn/dns-updown" CACHE 
STRING "Default location for the DNS up/down script")

 set(PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/lib/openvpn/plugins" CACHE FILEPATH 
"Location of the plugin directory")
@@ -646,6 +648,15 @@
     src/openvpn/xkey_provider.c
     )

+if (ENABLE_FBOUNDS_SAFETY)
+    # Only buffer.c is built with -fbounds-safety for now. This applies to
+    # every target in this directory that compiles it, including unit tests.
+    set_source_files_properties(src/openvpn/buffer.c PROPERTIES
+        COMPILE_OPTIONS -fbounds-safety
+        COMPILE_DEFINITIONS OVPN_SUPPORT_FBOUNDS_SAFETY
+        )
+endif ()
+
 add_executable(openvpn ${SOURCE_FILES})

 add_library_deps(openvpn)
diff --git a/configure.ac b/configure.ac
index 0ac61b4..46b28f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1329,6 +1329,15 @@
 AC_SUBST([tmpfilesdir])

 AC_ARG_ENABLE(
+       [fbounds-safety],
+       [AS_HELP_STRING([--enable-fbounds-safety],
+                       [enable experimental Clang -fbounds-safety annotations 
@<:@default=no@:>@])],
+       [enable_fbounds_safety="$enableval"],
+       [enable_fbounds_safety="no"]
+)
+AM_CONDITIONAL([ENABLE_FBOUNDS_SAFETY], [test "${enable_fbounds_safety}" = 
"yes"])
+
+AC_ARG_ENABLE(
      [unit-tests],
      [AS_HELP_STRING([--disable-unit-tests],
                      [Disables building and running the unit tests suite])],
diff --git a/src/compat/compat.h b/src/compat/compat.h
index 4ee9141..20abf19 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -75,4 +75,53 @@
 strtok_r(char *s, const char *delim, char **last);
 #endif

+/*
+ * Optional Clang -fbounds-safety annotations. <ptrcheck.h> turns them into
+ * no-ops when -fbounds-safety is not enabled, and some system headers include
+ * it unconditionally, so prefer it when available and only fall back to our
+ * own no-op definitions for annotations that are still undefined.
+ */
+#if defined(OVPN_SUPPORT_FBOUNDS_SAFETY)
+#include <ptrcheck.h>
+#elif defined(__has_include)
+#if __has_include(<ptrcheck.h>)
+#include <ptrcheck.h>
+#endif
+#endif
+
+#ifndef __sized_by
+#define __sized_by(n)
+#endif
+#ifndef __sized_by_or_null
+#define __sized_by_or_null(n)
+#endif
+#ifndef __counted_by
+#define __counted_by(n)
+#endif
+#ifndef __counted_by_or_null
+#define __counted_by_or_null(n)
+#endif
+#ifndef __null_terminated
+#define __null_terminated
+#endif
+#ifndef __unsafe_indexable
+#define __unsafe_indexable
+#endif
+#ifndef __unsafe_forge_single
+#define __unsafe_forge_single(T, P) ((T)(P))
+#endif
+#ifndef __null_terminated_to_indexable
+#define __null_terminated_to_indexable(P) (P)
+#endif
+#ifndef __unsafe_null_terminated_to_indexable
+#define __unsafe_null_terminated_to_indexable(P) (P)
+#endif
+#ifndef __unsafe_null_terminated_from_indexable
+#define __unsafe_null_terminated_from_indexable(P) (P)
+#endif
+/* not defined by <ptrcheck.h> without -fbounds-safety as it changes the ABI */
+#ifndef __bidi_indexable
+#define __bidi_indexable
+#endif
+
 #endif /* COMPAT_H */
diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am
index 8a60a94..9a4e8b7 100644
--- a/src/openvpn/Makefile.am
+++ b/src/openvpn/Makefile.am
@@ -49,7 +49,7 @@
        auth_token.c auth_token.h \
        base64.c base64.h \
        basic.h \
-       buffer.c buffer.h \
+       buffer.h \
        check_file_access.c check_file_access.h \
        circ_list.h \
        clinat.c clinat.h \
@@ -162,7 +162,17 @@
        win32.h win32.c \
        win32-util.h win32-util.c \
        cryptoapi.h cryptoapi.c
-openvpn_LDADD = \
+if ENABLE_FBOUNDS_SAFETY
+# Only buffer.c is built with -fbounds-safety for now
+noinst_LTLIBRARIES = libbuffer.la
+libbuffer_la_SOURCES = buffer.c
+libbuffer_la_CFLAGS = $(AM_CFLAGS) -fbounds-safety 
-DOVPN_SUPPORT_FBOUNDS_SAFETY
+openvpn_LDADD = libbuffer.la
+else
+openvpn_SOURCES += buffer.c
+openvpn_LDADD =
+endif
+openvpn_LDADD += \
        $(top_builddir)/src/compat/libcompat.la \
        $(SOCKETS_LIBS) \
        $(OPTIONAL_LIBCAPNG_LIBS) \
diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index 8813fa5..1515ed7 100644
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -272,7 +272,7 @@
         size_t len = strlen(str) + 1;
         if (buf_size_valid(len) && (int)len < buf_forward_capacity_total(buf))
         {
-            memcpy(buf->data + buf->capacity - len, str, len);
+            memcpy(buf->data + buf->capacity - len, 
__unsafe_null_terminated_to_indexable(str), len);
         }
     }
 }
@@ -309,7 +309,7 @@
  * Garbage collection
  */

-void *
+void *__sized_by(size)
 gc_malloc(size_t size, bool clear, struct gc_arena *a)
 {
     void *ret;
@@ -403,7 +403,7 @@
 }

 void
-gc_addspecial(void *addr, void (*free_function)(void *), struct gc_arena *a)
+gc_addspecial(void *addr, void (*free_function)(void *__unsafe_indexable), 
struct gc_arena *a)
 {
     ASSERT(a);
     struct gc_entry_special *e;
@@ -444,7 +444,7 @@
  */

 char *
-format_hex_ex(const uint8_t *data, size_t size, size_t maxoutput, unsigned int 
space_break_flags,
+format_hex_ex(const uint8_t *__counted_by(size) data, size_t size, size_t 
maxoutput, unsigned int space_break_flags,
               const char *separator, struct gc_arena *gc)
 {
     const size_t bytes_per_hexblock = space_break_flags & FHE_SPACE_BREAK_MASK;
@@ -576,7 +576,7 @@
  * Remove trailing \r and \n chars.
  */
 void
-chomp(char *str)
+chomp(char *__null_terminated str)
 {
     rm_trailing_chars(str, "\r\n");
 }
@@ -585,19 +585,20 @@
  * Remove trailing chars
  */
 void
-rm_trailing_chars(char *str, const char *what_to_delete)
+rm_trailing_chars(char *__null_terminated str, const char *what_to_delete)
 {
+    char *cp = __null_terminated_to_indexable(str);
     size_t len = strlen(str);
-    while (len > 0 && strchr(what_to_delete, str[len - 1]) != NULL)
+    while (len > 0 && strchr(what_to_delete, cp[len - 1]) != NULL)
     {
-        str[--len] = '\0';
+        cp[--len] = '\0';
     }
 }

 /*
  * Allocate a string
  */
-char *
+char *__null_terminated
 string_alloc(const char *str, struct gc_arena *gc)
 {
     if (str)
@@ -618,8 +619,8 @@
             ret = calloc(1, n);
             check_malloc_return(ret);
         }
-        memcpy(ret, str, n);
-        return ret;
+        memcpy(ret, __unsafe_null_terminated_to_indexable(str), n);
+        return __unsafe_null_terminated_from_indexable(ret);
     }
     else
     {
@@ -631,11 +632,11 @@
  * Erase all characters in a string
  */
 void
-string_clear(char *str)
+string_clear(char *__null_terminated str)
 {
     if (str)
     {
-        secure_memzero(str, strlen(str));
+        secure_memzero(__null_terminated_to_indexable(str), strlen(str));
     }
 }

@@ -643,7 +644,7 @@
  * Return the length of a string array
  */
 int
-string_array_len(const char **array)
+string_array_len(const char **__null_terminated array)
 {
     int i = 0;
     if (array)
@@ -657,13 +658,13 @@
 }

 char *
-print_argv(const char **p, struct gc_arena *gc, const unsigned int flags)
+print_argv(const char **__null_terminated p, struct gc_arena *gc, const 
unsigned int flags)
 {
     struct buffer out = alloc_buf_gc(256, gc);
     int i = 0;
     for (; *p; ++p)
     {
-        const char *cp = *p;
+        const char *__null_terminated cp = *p;
         if (i)
         {
             buf_printf(&out, " ");
@@ -691,8 +692,8 @@

     ASSERT(str);

-    const char *copy = string_alloc(str, gc);
-    buf_set_read(&buf, (const uint8_t *)copy, strlen(str) + 1);
+    const char *__null_terminated copy = string_alloc(str, gc);
+    buf_set_read(&buf, (const uint8_t 
*)__unsafe_null_terminated_to_indexable(copy), strlen(str) + 1);
 
     if (buf.len > 0) /* Don't count trailing '\0' as part of length */
     {
@@ -714,7 +715,7 @@
     {
         return false;
     }
-    return memcmp(CBPTR(src), match, size) == 0;
+    return memcmp(CBPTR(src), __null_terminated_to_indexable(match), size) == 
0;
 }

 bool
@@ -754,7 +755,7 @@
  */

 bool
-buf_parse(struct buffer *buf, const int delim, char *line, const int size)
+buf_parse(struct buffer *buf, const int delim, char *__counted_by(size) line, 
const int size)
 {
     bool eol = false;
     int n = 0;
@@ -983,12 +984,13 @@
  * Guaranteed to not increase string length.
  */
 bool
-string_mod(char *str, const unsigned int inclusive, const unsigned int 
exclusive,
+string_mod(char *__null_terminated str, const unsigned int inclusive, const 
unsigned int exclusive,
            const char replace)
 {
     ASSERT(str);

-    char *out = str;
+    /* the terminator is rewritten in place, so it needs to be within bounds */
+    char *out = __unsafe_null_terminated_to_indexable(str);
     const char *in = out;
     bool ret = true;

@@ -1039,7 +1041,7 @@
 {
     if (str)
     {
-        char *buf = string_alloc(str, gc);
+        char *__null_terminated buf = string_alloc(str, gc);
         string_mod(buf, inclusive, exclusive, replace);
         return buf;
     }
@@ -1050,7 +1052,7 @@
 }

 void
-string_replace_leading(char *str, const char match, const char replace)
+string_replace_leading(char *__null_terminated str, const char match, const 
char replace)
 {
     ASSERT(match != '\0');
     while (*str)
@@ -1112,7 +1114,7 @@
 }

 bool
-checked_snprintf(char *str, size_t size, const char *format, ...)
+checked_snprintf(char *__counted_by(size) str, size_t size, const char 
*format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -1192,7 +1194,8 @@
     if (str)
     {
         const size_t len = strlen((const char *)str);
-        struct buffer_entry *e = buffer_list_push_data(ol, str, len + 1);
+        struct buffer_entry *e =
+            buffer_list_push_data(ol, 
__unsafe_null_terminated_to_indexable(str), len + 1);
         if (e)
         {
             e->buf.len--; /* Don't count trailing '\0' as part of length */
@@ -1201,7 +1204,7 @@
 }

 struct buffer_entry *
-buffer_list_push_data(struct buffer_list *ol, const void *data, size_t size)
+buffer_list_push_data(struct buffer_list *ol, const void *__sized_by(size) 
data, size_t size)
 {
     struct buffer_entry *e = NULL;
     if (data)
@@ -1271,7 +1274,7 @@
         {
             struct buffer_entry *next = e->next;
             buf_copy(&f->buf, &e->buf);
-            buf_write(&f->buf, sep, sep_len);
+            buf_write(&f->buf, __null_terminated_to_indexable(sep), sep_len);
             free_buf(&e->buf);
             free(e);
             e = next;
@@ -1337,7 +1340,7 @@
             bl = buffer_list_new();
             while (fgets(line, max_line_len, fp) != NULL)
             {
-                buffer_list_push(bl, line);
+                buffer_list_push(bl, 
__unsafe_null_terminated_from_indexable(line));
             }
             free(line);
         }
diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index 7af4444..bf8d02c 100644
--- a/src/openvpn/buffer.h
+++ b/src/openvpn/buffer.h
@@ -69,13 +69,14 @@
  */
 struct buffer
 {
-    int capacity;  /**< Size in bytes of memory allocated by
-                    *   \c malloc(). */
-    int offset;    /**< Offset in bytes of the actual content
-                    *   within the allocated memory. */
-    int len;       /**< Length in bytes of the actual content
-                    *   within the allocated memory. */
-    uint8_t *data; /**< Pointer to the allocated memory. */
+    int capacity; /**< Size in bytes of memory allocated by
+                   *   \c malloc(). */
+    int offset;   /**< Offset in bytes of the actual content
+                   *   within the allocated memory. */
+    int len;      /**< Length in bytes of the actual content
+                   *   within the allocated memory. */
+    /** Pointer to the allocated memory. */
+    uint8_t *__sized_by_or_null(capacity) data;

 #ifdef BUF_INIT_TRACKING
     const char *debug_file;
@@ -108,7 +109,7 @@
 struct gc_entry_special
 {
     struct gc_entry_special *next;
-    void (*free_fnc)(void *);
+    void (*free_fnc)(void *__unsafe_indexable);
     void *addr;
 };

@@ -199,7 +200,7 @@
  *
  * @param str   The string to clear.
  */
-void string_clear(char *str);
+void string_clear(char *__null_terminated str);

 /**
  * Return the number of elements in a NULL-terminated array of strings.
@@ -208,7 +209,7 @@
  *
  * @return Number of non-NULL elements.
  */
-int string_array_len(const char **array);
+int string_array_len(const char **__null_terminated array);

 /**
  * Safely compute the product of two sizes plus an extra amount.
@@ -236,7 +237,7 @@
  *
  * @return Newly allocated string representation of \c p.
  */
-char *print_argv(const char **p, struct gc_arena *gc, const unsigned int 
flags);
+char *print_argv(const char **__null_terminated p, struct gc_arena *gc, const 
unsigned int flags);

 /**
  * Report a buffer size error and abort.
@@ -299,7 +300,7 @@
  *
  * @return Pointer to the newly allocated memory.
  */
-void *gc_malloc(size_t size, bool clear, struct gc_arena *a);
+void *__sized_by(size) gc_malloc(size_t size, bool clear, struct gc_arena *a);

 /**
  * Duplicate a string, allocating memory under garbage collection.
@@ -311,7 +312,7 @@
  *
  * @return A newly allocated copy of \c str, or NULL if \c str is NULL.
  */
-char *string_alloc(const char *str, struct gc_arena *gc);
+char *__null_terminated string_alloc(const char *str, struct gc_arena *gc);

 /**
  * Allocate a buffer containing a copy of the given string.
@@ -337,10 +338,12 @@
  * something other than plain \c free(), such as \c freeaddrinfo().
  *
  * @param addr          Pointer to the memory to register.
- * @param free_function Function to call to free \c addr.
+ * @param free_function Function to call to free \c addr.  The parameter is
+ *                      \c __unsafe_indexable so that \c free() can be passed
+ *                      with -fbounds-safety.
  * @param a             Garbage collection arena to register with.
  */
-void gc_addspecial(void *addr, void (*free_function)(void *), struct gc_arena 
*a);
+void gc_addspecial(void *addr, void (*free_function)(void 
*__unsafe_indexable), struct gc_arena *a);

 /**
  * allows to realloc a pointer previously allocated by gc_malloc or gc_realloc
@@ -374,9 +377,9 @@
  * @param addr  Pointer to the \c struct \c addrinfo to free.
  */
 static inline void
-gc_freeaddrinfo_callback(void *addr)
+gc_freeaddrinfo_callback(void *__unsafe_indexable addr)
 {
-    freeaddrinfo((struct addrinfo *)addr);
+    freeaddrinfo(__unsafe_forge_single(struct addrinfo *, addr));
 }

 /** Return an empty, undefined \c struct \c buffer (all fields zero). */
@@ -424,7 +427,7 @@
  * @return Pointer to \c buf->data + \c buf->offset, or NULL if \c buf is
  *         not valid.
  */
-static inline const uint8_t *
+static inline const uint8_t *__bidi_indexable
 buf_cbptr(const struct buffer *buf)
 {
     if (buf_valid(buf))
@@ -445,7 +448,7 @@
  * @return Pointer to \c buf->data + \c buf->offset, or NULL if \c buf is
  *         not valid.
  */
-static inline uint8_t *
+static inline uint8_t *__bidi_indexable
 buf_bptr(struct buffer *buf)
 {
     return (uint8_t *)buf_cbptr(buf);
@@ -478,7 +481,7 @@
  *
  * @return Pointer to the byte immediately after the last content byte.
  */
-static inline uint8_t *
+static inline uint8_t *__bidi_indexable
 buf_bend(struct buffer *buf)
 {
     return buf_bptr(buf) + buf_len(buf);
@@ -491,7 +494,7 @@
  *
  * @return Pointer to the byte immediately after the last content byte.
  */
-static inline const uint8_t *
+static inline const uint8_t *__bidi_indexable
 buf_cbend(const struct buffer *buf)
 {
     return buf_cbptr(buf) + buf_len(buf);
@@ -505,7 +508,7 @@
  * @return Pointer to the last byte, or NULL if the buffer is empty or
  *         invalid.
  */
-static inline const uint8_t *
+static inline const uint8_t *__bidi_indexable
 buf_cblast(const struct buffer *buf)
 {
     if (buf_len(buf) > 0)
@@ -526,7 +529,7 @@
  * @return Pointer to the last byte, or NULL if the buffer is empty or
  *         invalid.
  */
-static inline uint8_t *
+static inline uint8_t *__bidi_indexable
 buf_blast(struct buffer *buf)
 {
     return (uint8_t *)buf_cblast(buf);
@@ -568,7 +571,7 @@
  *
  * @return The content pointer as a \c char *, or NULL if \c buf is invalid.
  */
-static inline char *
+static inline char *__bidi_indexable
 buf_str(struct buffer *buf)
 {
     return (char *)buf_bptr(buf);
@@ -581,7 +584,7 @@
  *
  * @return The content pointer as a \c const char *, or NULL if \c buf is 
invalid.
  */
-static inline const char *
+static inline const char *__bidi_indexable
 buf_cstr(const struct buffer *buf)
 {
     return (const char *)buf_cbptr(buf);
@@ -655,7 +658,7 @@
  * @param size  Size of the memory region in bytes.
  */
 static inline void
-buf_set_write(struct buffer *buf, uint8_t *data, int size)
+buf_set_write(struct buffer *buf, uint8_t *__sized_by_or_null(size) data, int 
size)
 {
     if (!buf_size_valid(size))
     {
@@ -684,7 +687,7 @@
  * @param size  Size of the memory region in bytes.
  */
 static inline void
-buf_set_read(struct buffer *buf, const uint8_t *data, size_t size)
+buf_set_read(struct buffer *buf, const uint8_t *__sized_by_or_null(size) data, 
size_t size)
 {
     if (!buf_size_valid(size))
     {
@@ -745,13 +748,13 @@
  * @param len   Length of data, in bytes.
  */
 static inline void
-secure_memzero(void *data, size_t len)
+secure_memzero(void *__sized_by(len) data, size_t len)
 {
 #if defined(_WIN32)
     SecureZeroMemory(data, len);
 #elif defined(__GNUC__) || defined(__clang__)
     memset(data, 0, len);
-    __asm__ __volatile__("" : : "r"(data) : "memory");
+    __asm__ __volatile__("" : : "r"(__unsafe_forge_single(void *, data)) : 
"memory");
 #else
     volatile char *p = (volatile char *)data;
     while (len--)
@@ -836,7 +839,7 @@
  *
  * @param str   The null-terminated string to chomp.
  */
-void chomp(char *str);
+void chomp(char *__null_terminated str);

 /**
  * Remove all trailing characters that appear in a given set.
@@ -844,7 +847,7 @@
  * @param str             The null-terminated string to modify in place.
  * @param what_to_delete  Null-terminated set of characters to strip.
  */
-void rm_trailing_chars(char *str, const char *what_to_delete);
+void rm_trailing_chars(char *__null_terminated str, const char 
*what_to_delete);

 /**
  * Return a pointer past any leading whitespace in a string.
@@ -913,7 +916,7 @@
  *         extracted; true otherwise (including when a delimiter was found
  *         or \c line was truncated).
  */
-bool buf_parse(struct buffer *buf, const int delim, char *line, const int 
size);
+bool buf_parse(struct buffer *buf, const int delim, char *__counted_by(size) 
line, const int size);

 /** @name Hex Dump
  *  @brief Output a binary buffer to a hex string and return it.
@@ -941,7 +944,7 @@
  *
  * @return Null-terminated hex string allocated from \c gc.
  */
-char *format_hex_ex(const uint8_t *data, size_t size, size_t maxoutput, 
unsigned int space_break_flags,
+char *format_hex_ex(const uint8_t *__counted_by(size) data, size_t size, 
size_t maxoutput, unsigned int space_break_flags,
                     const char *separator, struct gc_arena *gc);

 /**
@@ -957,7 +960,7 @@
  * @return Null-terminated hex string allocated from \c gc.
  */
 static inline char *
-format_hex(const uint8_t *data, size_t size, size_t maxoutput, struct gc_arena 
*gc)
+format_hex(const uint8_t *__counted_by(size) data, size_t size, size_t 
maxoutput, struct gc_arena *gc)
 {
     return format_hex_ex(data, size, maxoutput, 4, " ", gc);
 }
@@ -1138,7 +1141,7 @@
  * @return Pointer to the newly reserved space (new content start), or NULL
  *         if \c buf is invalid or there is insufficient prepend capacity.
  */
-static inline uint8_t *
+static inline uint8_t *__bidi_indexable
 buf_prepend(struct buffer *buf, ssize_t size)
 {
     if (!buf_valid(buf) || size < 0 || size > buf->offset)
@@ -1185,7 +1188,7 @@
  * @return Pointer to the start of the reserved space, or NULL if there is
  *         insufficient capacity.
  */
-static inline uint8_t *
+static inline uint8_t *__bidi_indexable
 buf_write_alloc(struct buffer *buf, size_t size)
 {
     uint8_t *ret;
@@ -1210,7 +1213,7 @@
  * @return Pointer to the start of the consumed region, or NULL if \c size
  *         is negative or exceeds the current length.
  */
-static inline uint8_t *
+static inline uint8_t *__bidi_indexable
 buf_read_alloc(struct buffer *buf, int size)
 {
     uint8_t *ret;
@@ -1236,7 +1239,7 @@
  * @return true on success, false if there is insufficient capacity.
  */
 static inline bool
-buf_write(struct buffer *dest, const void *src, size_t size)
+buf_write(struct buffer *dest, const void *__sized_by(size) src, size_t size)
 {
     uint8_t *cp = buf_write_alloc(dest, size);
     if (!cp)
@@ -1260,7 +1263,7 @@
  * @return true on success, false if there is insufficient prepend capacity.
  */
 static inline bool
-buf_write_prepend(struct buffer *dest, const void *src, int size)
+buf_write_prepend(struct buffer *dest, const void *__sized_by(size) src, int 
size)
 {
     uint8_t *cp = buf_prepend(dest, size);
     if (!cp)
@@ -1448,7 +1451,7 @@
  * @return true on success, false if \c src has fewer than \c size bytes.
  */
 static inline bool
-buf_read(struct buffer *src, void *dest, int size)
+buf_read(struct buffer *src, void *__sized_by(size) dest, int size)
 {
     const uint8_t *cp = buf_read_alloc(src, size);
     if (!cp)
@@ -1596,7 +1599,7 @@
  * *NOT* constant time. Do not use when comparing HMACs.
  */
 static inline bool
-buf_string_match(const struct buffer *src, const void *match, int size)
+buf_string_match(const struct buffer *src, const void *__sized_by(size) match, 
int size)
 {
     if (size != src->len)
     {
@@ -1610,7 +1613,7 @@
  * *NOT* constant time. Do not use when comparing HMACs.
  */
 static inline bool
-buf_string_match_head(const struct buffer *src, const void *match, int size)
+buf_string_match_head(const struct buffer *src, const void *__sized_by(size) 
match, int size)
 {
     if (size < 0 || size > src->len)
     {
@@ -1749,7 +1752,7 @@
  * @param replace The character to replace the specified character classes 
with.
  * @return True if the string was not modified, false otherwise.
  */
-bool string_mod(char *str, const unsigned int inclusive, const unsigned int 
exclusive,
+bool string_mod(char *__null_terminated str, const unsigned int inclusive, 
const unsigned int exclusive,
                 const char replace);


@@ -1793,7 +1796,7 @@
  * @param match    The character to replace.
  * @param replace  The replacement character.
  */
-void string_replace_leading(char *str, const char match, const char replace);
+void string_replace_leading(char *__null_terminated str, const char match, 
const char replace);

 /**
  * Return true iff \c str starts with \c prefix.
@@ -1836,7 +1839,7 @@
  *
  * @return true if snprintf() was successful and not truncated.
  */
-bool checked_snprintf(char *str, size_t size, const char *format, ...)
+bool checked_snprintf(char *__counted_by(size) str, size_t size, const char 
*format, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 3, 4)))
@@ -2210,7 +2213,7 @@
  *
  * @return the new buffer
  */
-struct buffer_entry *buffer_list_push_data(struct buffer_list *ol, const void 
*data, size_t size);
+struct buffer_entry *buffer_list_push_data(struct buffer_list *ol, const void 
*__sized_by(size) data, size_t size);

 /**
  * Retrieve the head buffer

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2035?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib57d973a2f8ef48c3710f7d034da1a91c64d4755
Gerrit-Change-Number: 2035
Gerrit-PatchSet: 1
Gerrit-Owner: Laptops <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to