]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix format spec errors in Windows builds
authorSelva Nair <selva.nair@gmail.com>
Thu, 22 Feb 2018 04:54:55 +0000 (23:54 -0500)
committerGert Doering <gert@greenie.muc.de>
Thu, 22 Feb 2018 15:26:25 +0000 (16:26 +0100)
- "%ll" is not supported by Windows run time, so use PRIi64
   and cast the variable to (int64_t) in output statements
   (as in commit 9ba36639abcac4367c8227d2dd87b18fb56267c4)

- Fix an instance of wchar_t * printed using %s -- should be %ls.

- Cast variables to int or unsigned int to match the output
  format spec when necessary.

- In route.c correct format of adapter_index (should be %lu) in a few
  places and remove some unnecessary casts to (unsigned int). Not
  all such instances are changed, only those related to adapter_index
  (for consistency) or close-by contexts are edited.

Most of these errors are seen in current Windows cross-compile,
but a few are triggered only if some DEBUG options are enabled.
Some are not in Windows specific paths. But for consistency, all uses
of %llu/%lld are removed. As these only affect log output, there are
no potential side effects.

Replacing long long by int64_t also has the advantage of avoiding
size ambiguity as long long is not guaranteed to be 64 bytes.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <1519275295-29121-1-git-send-email-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16522.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
14 files changed:
src/openvpn/error.c
src/openvpn/event.c
src/openvpn/forward.c
src/openvpn/misc.c
src/openvpn/multi.c
src/openvpn/otime.c
src/openvpn/packet_id.c
src/openvpn/reliable.c
src/openvpn/route.c
src/openvpn/shaper.c
src/openvpn/shaper.h
src/openvpn/socket.c
src/openvpn/ssl_openssl.c
src/openvpn/tun.c

index f337c447523dabcb3a272f82ef468c027b2b0716..d270ecb8b4699d104075482d0ae95bccae8ce407 100644 (file)
@@ -342,8 +342,8 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
                 struct timeval tv;
                 gettimeofday(&tv, NULL);
 
-                fprintf(fp, "%lld.%06ld %x %s%s%s%s",
-                        (long long)tv.tv_sec,
+                fprintf(fp, "%"PRIi64".%06ld %x %s%s%s%s",
+                        (int64_t)tv.tv_sec,
                         (long)tv.tv_usec,
                         flags,
                         prefix,
index 925dc88ec6c1290ffc0a3d84991595224b86ee49..372769057a966df62f5b04a2b004bca007c83df9 100644 (file)
@@ -1041,9 +1041,9 @@ se_wait_fast(struct event_set *es, const struct timeval *tv, struct event_set_re
     struct timeval tv_tmp = *tv;
     int stat;
 
-    dmsg(D_EVENT_WAIT, "SE_WAIT_FAST maxfd=%d tv=%lld/%ld",
+    dmsg(D_EVENT_WAIT, "SE_WAIT_FAST maxfd=%d tv=%"PRIi64"/%ld",
          ses->maxfd,
-         (long long)tv_tmp.tv_sec,
+         (int64_t)tv_tmp.tv_sec,
          (long)tv_tmp.tv_usec);
 
     stat = select(ses->maxfd + 1, &ses->readfds, &ses->writefds, NULL, &tv_tmp);
@@ -1065,8 +1065,8 @@ se_wait_scalable(struct event_set *es, const struct timeval *tv, struct event_se
     fd_set write = ses->writefds;
     int stat;
 
-    dmsg(D_EVENT_WAIT, "SE_WAIT_SCALEABLE maxfd=%d tv=%lld/%ld",
-         ses->maxfd, (long long)tv_tmp.tv_sec, (long)tv_tmp.tv_usec);
+    dmsg(D_EVENT_WAIT, "SE_WAIT_SCALEABLE maxfd=%d tv=%"PRIi64"/%ld",
+         ses->maxfd, (int64_t)tv_tmp.tv_sec, (long)tv_tmp.tv_usec);
 
     stat = select(ses->maxfd + 1, &read, &write, NULL, &tv_tmp);
 
index b5b9684e6e03fb71a4040847b4c54541d5045f14..7d9a338dcd47aa83be548553438df18fe3ddc2d8 100644 (file)
@@ -610,7 +610,7 @@ check_coarse_timers_dowork(struct context *c)
     process_coarse_timers(c);
     c->c2.coarse_timer_wakeup = now + c->c2.timeval.tv_sec;
 
-    dmsg(D_INTERVAL, "TIMER: coarse timer wakeup %lld seconds", (long long)c->c2.timeval.tv_sec);
+    dmsg(D_INTERVAL, "TIMER: coarse timer wakeup %"PRIi64" seconds", (int64_t)c->c2.timeval.tv_sec);
 
     /* Is the coarse timeout NOT the earliest one? */
     if (c->c2.timeval.tv_sec > save.tv_sec)
index 23e272cd29a9da4b2de3f37a0ed5a2342756d21f..72ffc406f3f631c4399ab42345b08ca14665414a 100644 (file)
@@ -556,7 +556,7 @@ void
 setenv_long_long(struct env_set *es, const char *name, long long value)
 {
     char buf[64];
-    openvpn_snprintf(buf, sizeof(buf), "%lld", value);
+    openvpn_snprintf(buf, sizeof(buf), "%"PRIi64, (int64_t)value);
     setenv_str(es, name, buf);
 }
 
index d5e8cbb795cb3ef304248bf6b6c414aa04ec9da8..6a72a1dcc13bde8da1cd2d76c7c833516f1406dd 100644 (file)
@@ -2383,13 +2383,13 @@ multi_process_post(struct multi_context *m, struct multi_instance *mi, const uns
         multi_set_pending(m, ANY_OUT(&mi->context) ? mi : NULL);
 
 #ifdef MULTI_DEBUG_EVENT_LOOP
-        printf("POST %s[%d] to=%d lo=%d/%d w=%lld/%ld\n",
+        printf("POST %s[%d] to=%d lo=%d/%d w=%"PRIi64"/%ld\n",
                id(mi),
                (int) (mi == m->pending),
                mi ? mi->context.c2.to_tun.len : -1,
                mi ? mi->context.c2.to_link.len : -1,
                (mi && mi->context.c2.fragment) ? mi->context.c2.fragment->outgoing.len : -1,
-               (long long)mi->context.c2.timeval.tv_sec,
+               (int64_t)mi->context.c2.timeval.tv_sec,
                (long)mi->context.c2.timeval.tv_usec);
 #endif
     }
index 303427717cf226c89b09886c87aaf80bfd5b49a3..e0b1b0eee748dd4c09078d6cc543c7a736234225 100644 (file)
@@ -88,8 +88,8 @@ const char *
 tv_string(const struct timeval *tv, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(64, gc);
-    buf_printf(&out, "[%lld/%ld]",
-               (long long)tv->tv_sec,
+    buf_printf(&out, "[%"PRIi64"/%ld]",
+               (int64_t)tv->tv_sec,
                (long)tv->tv_usec);
     return BSTR(&out);
 }
@@ -198,9 +198,9 @@ time_test(void)
         t = time(NULL);
         gettimeofday(&tv, NULL);
 #if 1
-        msg(M_INFO, "t=%lld s=%lld us=%ld",
-            (long long)t,
-            (long long)tv.tv_sec,
+        msg(M_INFO, "t=%"PRIi64" s=%"PRIi64" us=%ld",
+            (int64_t)t,
+            (int64_t)tv.tv_sec,
             (long)tv.tv_usec);
 #endif
     }
index b6ffa5aa2a3a87d127a02c00ee9abfd4c1581fd5..dc44f36bcaf60ce64997f22e57ecc1bfeb1087a2 100644 (file)
@@ -606,14 +606,14 @@ packet_id_debug_print(int msglevel,
         }
         buf_printf(&out, "%c", c);
     }
-    buf_printf(&out, "] %lld:" packet_id_format, (long long)p->time, (packet_id_print_type)p->id);
+    buf_printf(&out, "] %"PRIi64":" packet_id_format, (int64_t)p->time, (packet_id_print_type)p->id);
     if (pin)
     {
-        buf_printf(&out, " %lld:" packet_id_format, (long long)pin->time, (packet_id_print_type)pin->id);
+        buf_printf(&out, " %"PRIi64":" packet_id_format, (int64_t)pin->time, (packet_id_print_type)pin->id);
     }
 
-    buf_printf(&out, " t=%lld[%d]",
-               (long long)prev_now,
+    buf_printf(&out, " t=%"PRIi64"[%d]",
+               (int64_t)prev_now,
                (int)(prev_now - tv.tv_sec));
 
     buf_printf(&out, " r=[%d,%d,%d,%d,%d]",
@@ -666,8 +666,8 @@ packet_id_interactive_test(void)
         {
             packet_id_reap_test(&pid.rec);
             test = packet_id_test(&pid.rec, &pin);
-            printf("packet_id_test (%lld, " packet_id_format ") returned %d\n",
-                   (long long)pin.time,
+            printf("packet_id_test (%"PRIi64", " packet_id_format ") returned %d\n",
+                   (int64_t)pin.time,
                    (packet_id_print_type)pin.id,
                    test);
             if (test)
@@ -679,8 +679,8 @@ packet_id_interactive_test(void)
         {
             long_form = (count < 20);
             packet_id_alloc_outgoing(&pid.send, &pin, long_form);
-            printf("(%lld(" packet_id_format "), %d)\n",
-                   (long long)pin.time,
+            printf("(%"PRIi64"(" packet_id_format "), %d)\n",
+                   (int64_t)pin.time,
                    (packet_id_print_type)pin.id,
                    long_form);
             if (pid.send.id == 10)
index 51176418cc757bc78406a476655cca0093fff621..b62ab548dbc36a88b4f1f5c2c60fe0f551975dd2 100644 (file)
@@ -762,14 +762,14 @@ reliable_debug_print(const struct reliable *rel, char *desc)
     printf("********* struct reliable %s\n", desc);
     printf("  initial_timeout=%d\n", (int)rel->initial_timeout);
     printf("  packet_id=" packet_id_format "\n", rel->packet_id);
-    printf("  now=%lld\n", (long long)now);
+    printf("  now=%"PRIi64"\n", (int64_t)now);
     for (i = 0; i < rel->size; ++i)
     {
         const struct reliable_entry *e = &rel->array[i];
         if (e->active)
         {
             printf("  %d: packet_id=" packet_id_format " len=%d", i, e->packet_id, e->buf.len);
-            printf(" next_try=%lld", (long long)e->next_try);
+            printf(" next_try=%"PRIi64, (int64_t)e->next_try);
             printf("\n");
         }
     }
index ca8b182bd0baa8f5bd31ae5473098d9add398212..12bca1016665f147f58b7b58056a1290bbc8927f 100644 (file)
@@ -1322,7 +1322,7 @@ print_default_gateway(const int msglevel,
 #ifdef _WIN32
         if (rgi->flags & RGI_IFACE_DEFINED)
         {
-            buf_printf(&out, " I=%u", (unsigned int)rgi->adapter_index);
+            buf_printf(&out, " I=%lu", rgi->adapter_index);
         }
 #else
         if (rgi->flags & RGI_IFACE_DEFINED)
@@ -1353,7 +1353,7 @@ print_default_gateway(const int msglevel,
 #ifdef _WIN32
         if (rgi6->flags & RGI_IFACE_DEFINED)
         {
-            buf_printf(&out, " I=%u", (unsigned int)rgi6->adapter_index);
+            buf_printf(&out, " I=%lu", rgi6->adapter_index);
         }
 #else
         if (rgi6->flags & RGI_IFACE_DEFINED)
@@ -1627,7 +1627,7 @@ add_route(struct route_ipv4 *r,
         if (is_on_link(is_local_route, flags, rgi))
         {
             ai = rgi->adapter_index;
-            argv_printf_cat(&argv, "IF %u", (unsigned int)ai);
+            argv_printf_cat(&argv, "IF %lu", ai);
         }
 
         argv_msg(D_ROUTE, &argv);
@@ -1969,12 +1969,12 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flag
         struct buffer out = alloc_buf_gc(64, &gc);
         if (r6->adapter_index)          /* vpn server special route */
         {
-            buf_printf(&out, "interface=%d", r6->adapter_index );
+            buf_printf(&out, "interface=%lu", r6->adapter_index );
             gateway_needed = true;
         }
         else
         {
-            buf_printf(&out, "interface=%d", tt->adapter_index );
+            buf_printf(&out, "interface=%lu", tt->adapter_index );
         }
         device = buf_bptr(&out);
 
@@ -2416,12 +2416,12 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, unsigned
         struct buffer out = alloc_buf_gc(64, &gc);
         if (r6->adapter_index)          /* vpn server special route */
         {
-            buf_printf(&out, "interface=%d", r6->adapter_index );
+            buf_printf(&out, "interface=%lu", r6->adapter_index );
             gateway_needed = true;
         }
         else
         {
-            buf_printf(&out, "interface=%d", tt->adapter_index );
+            buf_printf(&out, "interface=%lu", tt->adapter_index );
         }
         device = buf_bptr(&out);
 
@@ -2841,7 +2841,7 @@ get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6,
         goto done;
     }
 
-    msg( D_ROUTE, "GDG6: II=%d DP=%s/%d NH=%s",
+    msg( D_ROUTE, "GDG6: II=%lu DP=%s/%d NH=%s",
          BestRoute.InterfaceIndex,
          print_in6_addr( BestRoute.DestinationPrefix.Prefix.Ipv6.sin6_addr, 0, &gc),
          BestRoute.DestinationPrefix.PrefixLength,
@@ -3002,7 +3002,7 @@ do_route_service(const bool add, const route_message_t *rt, const size_t size, H
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_WARN, "ROUTE: route %s failed using service: %s [status=%u if_index=%lu]",
+        msg(M_WARN, "ROUTE: route %s failed using service: %s [status=%u if_index=%d]",
             (add ? "addition" : "deletion"), strerror_win32(ack.error_number, &gc),
             ack.error_number, rt->iface.index);
         goto out;
index 1bf72aaca472f86c78d49369aaa21ec10b74973f..92364f29ab28d77419bf9ceccdbf2c4128b86ad2 100644 (file)
@@ -76,8 +76,8 @@ shaper_soonest_event(struct timeval *tv, int delay)
         }
     }
 #ifdef SHAPER_DEBUG
-    dmsg(D_SHAPER_DEBUG, "SHAPER shaper_soonest_event sec=%lld usec=%ld ret=%d",
-         (long long)tv->tv_sec, (long)tv->tv_usec, (int)ret);
+    dmsg(D_SHAPER_DEBUG, "SHAPER shaper_soonest_event sec=%"PRIi64" usec=%ld ret=%d",
+         (int64_t)tv->tv_sec, (long)tv->tv_usec, (int)ret);
 #endif
     return ret;
 }
index d290607880b517d060fea08321ff8c97c2273289..4efe398a27b05595db0c22e3534872f0f7992b12 100644 (file)
@@ -147,10 +147,10 @@ shaper_wrote_bytes(struct shaper *s, int nbytes)
         tv_add(&s->wakeup, &tv);
 
 #ifdef SHAPER_DEBUG
-        dmsg(D_SHAPER_DEBUG, "SHAPER shaper_wrote_bytes bytes=%d delay=%ld sec=%lld usec=%ld",
+        dmsg(D_SHAPER_DEBUG, "SHAPER shaper_wrote_bytes bytes=%d delay=%ld sec=%"PRIi64" usec=%ld",
              nbytes,
              (long)tv.tv_usec,
-             (long long)s->wakeup.tv_sec,
+             (int64_t)s->wakeup.tv_sec,
              (long)s->wakeup.tv_usec);
 #endif
     }
index 8445daacdf9739fa1f0edfdca0b9156a1887a2db..211e7441c0c9db581dc151c30121c00c2179c479 100644 (file)
@@ -1122,7 +1122,7 @@ socket_do_accept(socket_descriptor_t sd,
 
     if (!socket_defined(new_sd))
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "TCP: accept(%d) failed", sd);
+        msg(D_LINK_ERRORS | M_ERRNO, "TCP: accept(%d) failed", (int)sd);
     }
     /* only valid if we have remote_len_af!=0 */
     else if (remote_len_af && remote_len != remote_len_af)
@@ -1875,12 +1875,12 @@ phase2_inetd(struct link_socket *sock, const struct frame *frame,
                 sock->info.lsa->actual.dest.addr.sa.sa_family = local_addr.addr.sa.sa_family;
                 dmsg(D_SOCKET_DEBUG, "inetd(%s): using sa_family=%d from getsockname(%d)",
                      proto2ascii(sock->info.proto, sock->info.af, false),
-                     local_addr.addr.sa.sa_family, sock->sd);
+                     local_addr.addr.sa.sa_family, (int)sock->sd);
             }
             else
             {
                 msg(M_WARN, "inetd(%s): getsockname(%d) failed, using AF_INET",
-                    proto2ascii(sock->info.proto, sock->info.af, false), sock->sd);
+                    proto2ascii(sock->info.proto, sock->info.af, false), (int)sock->sd);
             }
         }
 #else  /* ifdef HAVE_GETSOCKNAME */
index cd41513163b2511e4261a15d7f27911d0aa343f9..d91458b0c9b67735f9a6e7987cb97da9cbaa77b8 100644 (file)
@@ -1580,8 +1580,8 @@ bio_debug_data(const char *mode, BIO *bio, const uint8_t *buf, int len, const ch
     if (len > 0)
     {
         open_biofp();
-        fprintf(biofp, "BIO_%s %s time=%lld bio=" ptr_format " len=%d data=%s\n",
-                mode, desc, (long long)time(NULL), (ptr_type)bio, len, format_hex(buf, len, 0, &gc));
+        fprintf(biofp, "BIO_%s %s time=%"PRIi64" bio=" ptr_format " len=%d data=%s\n",
+                mode, desc, (int64_t)time(NULL), (ptr_type)bio, len, format_hex(buf, len, 0, &gc));
         fflush(biofp);
     }
     gc_free(&gc);
@@ -1591,8 +1591,8 @@ static void
 bio_debug_oc(const char *mode, BIO *bio)
 {
     open_biofp();
-    fprintf(biofp, "BIO %s time=%lld bio=" ptr_format "\n",
-            mode, (long long)time(NULL), (ptr_type)bio);
+    fprintf(biofp, "BIO %s time=%"PRIi64" bio=" ptr_format "\n",
+            mode, (int64_t)time(NULL), (ptr_type)bio);
     fflush(biofp);
 }
 
index 253d884b9fc9ef475f21175073cb54722c09ecf0..8771bf3d8c572b5485fc712c05adce576ae941aa 100644 (file)
@@ -125,7 +125,7 @@ do_address_service(const bool add, const short family, const struct tuntap *tt)
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_WARN, "TUN: %s address failed using service: %s [status=%u if_index=%lu]",
+        msg(M_WARN, "TUN: %s address failed using service: %s [status=%u if_index=%d]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc),
             ack.error_number, addr.iface.index);
         goto out;
@@ -3791,7 +3791,7 @@ get_panel_reg(struct gc_arena *gc)
 
             if (status != ERROR_SUCCESS || name_type != REG_SZ)
             {
-                dmsg(D_REGISTRY, "Error opening registry key: %s\\%s\\%s",
+                dmsg(D_REGISTRY, "Error opening registry key: %s\\%s\\%ls",
                      NETWORK_CONNECTIONS_KEY, connection_string, name_string);
             }
             else
@@ -5560,7 +5560,7 @@ fork_dhcp_action(struct tuntap *tt)
         {
             buf_printf(&cmd, " --dhcp-renew");
         }
-        buf_printf(&cmd, " --dhcp-internal %u", (unsigned int)tt->adapter_index);
+        buf_printf(&cmd, " --dhcp-internal %lu", tt->adapter_index);
 
         fork_to_self(BSTR(&cmd));
         gc_free(&gc);
@@ -6043,16 +6043,16 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
 
             if (status == NO_ERROR)
             {
-                msg(M_INFO, "Successful ARP Flush on interface [%u] %s",
-                    (unsigned int)index,
+                msg(M_INFO, "Successful ARP Flush on interface [%lu] %s",
+                    index,
                     device_guid);
             }
             else if (status != -1)
             {
-                msg(D_TUNTAP_INFO, "NOTE: FlushIpNetTable failed on interface [%u] %s (status=%u) : %s",
-                    (unsigned int)index,
+                msg(D_TUNTAP_INFO, "NOTE: FlushIpNetTable failed on interface [%lu] %s (status=%lu) : %s",
+                    index,
                     device_guid,
-                    (unsigned int)status,
+                    status,
                     strerror_win32(status, &gc));
             }
         }
@@ -6123,12 +6123,12 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
             }
             else
             {
-                msg(M_FATAL, "ERROR: AddIPAddress %s/%s failed on interface %s, index=%d, status=%u (windows error: '%s') -- %s",
+                msg(M_FATAL, "ERROR: AddIPAddress %s/%s failed on interface %s, index=%lu, status=%lu (windows error: '%s') -- %s",
                     print_in_addr_t(tt->local, 0, &gc),
                     print_in_addr_t(tt->adapter_netmask, 0, &gc),
                     device_guid,
-                    (int)index,
-                    (unsigned int)status,
+                    index,
+                    status,
                     strerror_win32(status, &gc),
                     error_suffix);
             }