VCL/LDPRELOAD: Fix out-of-bounds access and inequality comparison coverity errors
[vpp.git] / src / vcl / vcom_socket_wrapper.c
index 19a775d..d73f4b2 100644 (file)
@@ -101,6 +101,8 @@ static pthread_mutex_t libc_symbol_binding_mutex = PTHREAD_MUTEX_INITIALIZER;
 #ifdef NDEBUG
 #define SWRAP_LOG(...)
 #else
+static unsigned int swrap_log_lvl = SWRAP_LOG_WARN;
+
 static void
 swrap_log (enum swrap_dbglvl_e dbglvl, const char *func,
           const char *format, ...)
@@ -113,13 +115,12 @@ PRINTF_ATTRIBUTE (3, 4);
 {
   char buffer[1024];
   va_list va;
-  unsigned int lvl = SWRAP_LOG_WARN;
 
   va_start (va, format);
   vsnprintf (buffer, sizeof (buffer), format, va);
   va_end (va);
 
-  if (lvl >= dbglvl)
+  if (dbglvl <= swrap_log_lvl)
     {
       switch (dbglvl)
        {
@@ -153,14 +154,11 @@ PRINTF_ATTRIBUTE (3, 4);
  * SWRAP LOADING LIBC FUNCTIONS
  *********************************************************/
 
-#ifdef HAVE_ACCEPT4
 typedef int (*__libc_accept4) (int sockfd,
                               struct sockaddr * addr,
                               socklen_t * addrlen, int flags);
-#else
 typedef int (*__libc_accept) (int sockfd,
                              struct sockaddr * addr, socklen_t * addrlen);
-#endif
 typedef int (*__libc_bind) (int sockfd,
                            const struct sockaddr * addr, socklen_t addrlen);
 typedef int (*__libc_close) (int fd);
@@ -281,11 +279,8 @@ typedef int (*__libc_ppoll) (struct pollfd * __fds, nfds_t __nfds,
 
 struct swrap_libc_symbols
 {
-#ifdef HAVE_ACCEPT4
   SWRAP_SYMBOL_ENTRY (accept4);
-#else
   SWRAP_SYMBOL_ENTRY (accept);
-#endif
   SWRAP_SYMBOL_ENTRY (bind);
   SWRAP_SYMBOL_ENTRY (close);
   SWRAP_SYMBOL_ENTRY (connect);
@@ -473,7 +468,6 @@ _swrap_bind_symbol (enum swrap_lib lib, const char *fn_name)
  * has probably something todo with with the linker.
  * So we need load each function at the point it is called the first time.
  */
-#ifdef HAVE_ACCEPT4
 int
 libc_accept4 (int sockfd,
              struct sockaddr *addr, socklen_t * addrlen, int flags)
@@ -483,8 +477,6 @@ libc_accept4 (int sockfd,
   return swrap.libc.symbols._libc_accept4.f (sockfd, addr, addrlen, flags);
 }
 
-#else /* HAVE_ACCEPT4 */
-
 int
 libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen)
 {
@@ -492,7 +484,6 @@ libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen)
 
   return swrap.libc.symbols._libc_accept.f (sockfd, addr, addrlen);
 }
-#endif /* HAVE_ACCEPT4 */
 
 int
 libc_bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)