[Openvpn-devel,v2] Replace buffer backed strings for management_android_control with simple stack variables

Message ID 1516185516-28125-1-git-send-email-arne@rfc2549.org
State Accepted
Headers show
Series
  • [Openvpn-devel,v2] Replace buffer backed strings for management_android_control with simple stack variables
Related show

Commit Message

Arne Schwabe Jan. 17, 2018, 10:38 a.m.
This simplifies the code a bit and also silences compiler warnings about uint8_t pointers passed to char pointers without cast

Patch V2: Use openvpn_snprintf instead snprintf
---
 src/openvpn/route.c | 14 +++++++-------
 src/openvpn/tun.c   | 12 ++++++------
 2 files changed, 13 insertions(+), 13 deletions(-)

Comments

Gert Doering Jan. 17, 2018, 11:27 a.m. | #1
Acked-By: Gert Doering <gert@greenie.muc.de>

Patch looks reasonable, and is inside TARGET_ANDROID anyway, so if you
break it, it's your bug reports...

Your patch has been applied to the master branch.

commit 8fcc63b2e7d24d2fbf6d7ab10767c2347c723d31
Author: Arne Schwabe
Date:   Wed Jan 17 11:38:36 2018 +0100

     Replace buffer backed strings for management_android_control with simple stack variables

     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <1516185516-28125-1-git-send-email-arne@rfc2549.org>
     URL: https://www.mail-archive.com/search?l=mid&q=1516185516-28125-1-git-send-email-arne@rfc2549.org
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Patch

diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index 2bd5845b..1e1f204d 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -1610,17 +1610,17 @@  add_route(struct route_ipv4 *r,
     status = openvpn_execve_check(&argv, es, 0, "ERROR: Linux route add command failed");
 
 #elif defined (TARGET_ANDROID)
-    struct buffer out = alloc_buf_gc(128, &gc);
+    char out[128];
 
     if (rgi)
     {
-        buf_printf(&out, "%s %s %s dev %s", network, netmask, gateway, rgi->iface);
+        openvpn_snprintf(out, sizeof(out), "%s %s %s dev %s", network, netmask, gateway, rgi->iface);
     }
     else
     {
-        buf_printf(&out, "%s %s %s", network, netmask, gateway);
+        openvpn_snprintf(out, sizeof(out), "%s %s %s", network, netmask, gateway);
     }
-    management_android_control(management, "ROUTE", buf_bptr(&out));
+    management_android_control(management, "ROUTE", out);
 
 #elif defined (_WIN32)
     {
@@ -1963,11 +1963,11 @@  add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flag
     status = openvpn_execve_check(&argv, es, 0, "ERROR: Linux route -6/-A inet6 add command failed");
 
 #elif defined (TARGET_ANDROID)
-    struct buffer out = alloc_buf_gc(64, &gc);
+    char out[64];
 
-    buf_printf(&out, "%s/%d %s", network, r6->netbits, device);
+    openvpn_snprintf(out, sizeof(out), "%s/%d %s", network, r6->netbits, device);
 
-    management_android_control(management, "ROUTE6", buf_bptr(&out));
+    management_android_control(management, "ROUTE6", out);
 
 #elif defined (_WIN32)
 
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 6e163489..2644d996 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -1031,12 +1031,12 @@  do_ifconfig(struct tuntap *tt,
 
         if (do_ipv6)
         {
-            struct buffer out6 = alloc_buf_gc(64, &gc);
-            buf_printf(&out6, "%s/%d", ifconfig_ipv6_local,tt->netbits_ipv6);
-            management_android_control(management, "IFCONFIG6",buf_bptr(&out6));
+            char out6[64];
+            openvpn_snprintf(out6, sizeof(out6), "%s/%d", ifconfig_ipv6_local,tt->netbits_ipv6);
+            management_android_control(management, "IFCONFIG6", out6);
         }
 
-        struct buffer out = alloc_buf_gc(64, &gc);
+        char out[64];
 
         char *top;
         switch (tt->topology)
@@ -1057,8 +1057,8 @@  do_ifconfig(struct tuntap *tt,
                 top = "undef";
         }
 
-        buf_printf(&out, "%s %s %d %s", ifconfig_local, ifconfig_remote_netmask, tun_mtu, top);
-        management_android_control(management, "IFCONFIG", buf_bptr(&out));
+        openvpn_snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local, ifconfig_remote_netmask, tun_mtu, top);
+        management_android_control(management, "IFCONFIG", out);
 
 #elif defined(TARGET_SOLARIS)
         /* Solaris 2.6 (and 7?) cannot set all parameters in one go...