[Openvpn-devel,v2] add support for %lu in argv_printf and prevent ASSERT

Message ID 20180623021147.22792-1-a@unstable.cc
State Accepted
Headers show
Series
  • [Openvpn-devel,v2] add support for %lu in argv_printf and prevent ASSERT
Related show

Commit Message

Antonio Quartulli June 23, 2018, 2:11 a.m.
%lu is not supported by our tiny argv_printf implementation, therefore
it will trigger an ASSERT() when parsing it at route.c:1638.

Add support for '%lu' in argv_print() and prevent the ASSERT from being
triggered.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
---

It seems I managed to trigger this ASSERT when connecting to my v6-only
server with "gateway-redirect !ipv4 ipv6" set. Not sure why this issue
hasn't surfaced earlier though.


Changes from v1:
- keep format string as "%lu" but add support for it in argv_printf()
- tested on Windows 10 on top of the ipv6-only branch

 src/openvpn/argv.c | 7 +++++++
 1 file changed, 7 insertions(+)

Patch

diff --git a/src/openvpn/argv.c b/src/openvpn/argv.c
index dec7e3bf..9100a196 100644
--- a/src/openvpn/argv.c
+++ b/src/openvpn/argv.c
@@ -251,6 +251,13 @@  argv_printf_arglist(struct argv *a, const char *format, va_list arglist)
                 openvpn_snprintf(numstr, sizeof(numstr), "%u", va_arg(arglist, unsigned int));
                 argv_append(a, string_alloc(numstr, NULL));
             }
+            else if (!strcmp(term, "%lu"))
+            {
+                char numstr[64];
+                openvpn_snprintf(numstr, sizeof(numstr), "%lu",
+                                 va_arg(arglist, unsigned long));
+                argv_append(a, string_alloc(numstr, NULL));
+            }
             else if (!strcmp(term, "%s/%d"))
             {
                 char numstr[64];