Browse code

Replace buffer backed strings for management_android_control with simple stack variables

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
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>

Arne Schwabe authored on 2018/01/17 19:38:36
Showing 2 changed files
... ...
@@ -1599,17 +1599,17 @@ add_route(struct route_ipv4 *r,
1599 1599
     status = openvpn_execve_check(&argv, es, 0, "ERROR: Linux route add command failed");
1600 1600
 
1601 1601
 #elif defined (TARGET_ANDROID)
1602
-    struct buffer out = alloc_buf_gc(128, &gc);
1602
+    char out[128];
1603 1603
 
1604 1604
     if (rgi)
1605 1605
     {
1606
-        buf_printf(&out, "%s %s %s dev %s", network, netmask, gateway, rgi->iface);
1606
+        openvpn_snprintf(out, sizeof(out), "%s %s %s dev %s", network, netmask, gateway, rgi->iface);
1607 1607
     }
1608 1608
     else
1609 1609
     {
1610
-        buf_printf(&out, "%s %s %s", network, netmask, gateway);
1610
+        openvpn_snprintf(out, sizeof(out), "%s %s %s", network, netmask, gateway);
1611 1611
     }
1612
-    management_android_control(management, "ROUTE", buf_bptr(&out));
1612
+    management_android_control(management, "ROUTE", out);
1613 1613
 
1614 1614
 #elif defined (_WIN32)
1615 1615
     {
... ...
@@ -1952,11 +1952,11 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flag
1952 1952
     status = openvpn_execve_check(&argv, es, 0, "ERROR: Linux route -6/-A inet6 add command failed");
1953 1953
 
1954 1954
 #elif defined (TARGET_ANDROID)
1955
-    struct buffer out = alloc_buf_gc(64, &gc);
1955
+    char out[64];
1956 1956
 
1957
-    buf_printf(&out, "%s/%d %s", network, r6->netbits, device);
1957
+    openvpn_snprintf(out, sizeof(out), "%s/%d %s", network, r6->netbits, device);
1958 1958
 
1959
-    management_android_control(management, "ROUTE6", buf_bptr(&out));
1959
+    management_android_control(management, "ROUTE6", out);
1960 1960
 
1961 1961
 #elif defined (_WIN32)
1962 1962
 
... ...
@@ -1031,12 +1031,12 @@ do_ifconfig(struct tuntap *tt,
1031 1031
 
1032 1032
         if (do_ipv6)
1033 1033
         {
1034
-            struct buffer out6 = alloc_buf_gc(64, &gc);
1035
-            buf_printf(&out6, "%s/%d", ifconfig_ipv6_local,tt->netbits_ipv6);
1036
-            management_android_control(management, "IFCONFIG6",buf_bptr(&out6));
1034
+            char out6[64];
1035
+            openvpn_snprintf(out6, sizeof(out6), "%s/%d", ifconfig_ipv6_local,tt->netbits_ipv6);
1036
+            management_android_control(management, "IFCONFIG6", out6);
1037 1037
         }
1038 1038
 
1039
-        struct buffer out = alloc_buf_gc(64, &gc);
1039
+        char out[64];
1040 1040
 
1041 1041
         char *top;
1042 1042
         switch (tt->topology)
... ...
@@ -1057,8 +1057,8 @@ do_ifconfig(struct tuntap *tt,
1057 1057
                 top = "undef";
1058 1058
         }
1059 1059
 
1060
-        buf_printf(&out, "%s %s %d %s", ifconfig_local, ifconfig_remote_netmask, tun_mtu, top);
1061
-        management_android_control(management, "IFCONFIG", buf_bptr(&out));
1060
+        openvpn_snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local, ifconfig_remote_netmask, tun_mtu, top);
1061
+        management_android_control(management, "IFCONFIG", out);
1062 1062
 
1063 1063
 #elif defined(TARGET_SOLARIS)
1064 1064
         /* Solaris 2.6 (and 7?) cannot set all parameters in one go...