[Openvpn-devel] Use long long to format time_t-related environment variables

Message ID 20171105094641.55673-1-jca@wxcvbn.org
State Accepted
Headers show
Series
  • [Openvpn-devel] Use long long to format time_t-related environment variables
Related show

Commit Message

Jeremie Courreges-Anglas Nov. 5, 2017, 9:46 a.m.
Signed-off-by: Jeremie Courreges-Anglas <jca@wxcvbn.org>
---
 src/openvpn/misc.c    | 4 ++--
 src/openvpn/misc.h    | 2 +-
 src/openvpn/multi.c   | 7 ++-----
 src/openvpn/options.c | 2 +-
 4 files changed, 6 insertions(+), 9 deletions(-)

Comments

Steffan Karger Nov. 10, 2017, 11:31 a.m. | #1
Hi,

On 05-11-17 10:46, Jeremie Courreges-Anglas wrote:
> Signed-off-by: Jeremie Courreges-Anglas <jca@wxcvbn.org>
> ---
>  src/openvpn/misc.c    | 4 ++--
>  src/openvpn/misc.h    | 2 +-
>  src/openvpn/multi.c   | 7 ++-----
>  src/openvpn/options.c | 2 +-
>  4 files changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c
> index 8c7f6116..001fe1c4 100644
> --- a/src/openvpn/misc.c
> +++ b/src/openvpn/misc.c
> @@ -553,10 +553,10 @@ setenv_int(struct env_set *es, const char *name, int value)
>  }
>  
>  void
> -setenv_unsigned(struct env_set *es, const char *name, unsigned int value)
> +setenv_long_long(struct env_set *es, const char *name, long long value)
>  {
>      char buf[64];
> -    openvpn_snprintf(buf, sizeof(buf), "%u", value);
> +    openvpn_snprintf(buf, sizeof(buf), "%lld", value);
>      setenv_str(es, name, buf);
>  }
>  
> diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h
> index eb39ce3f..f6c810a2 100644
> --- a/src/openvpn/misc.h
> +++ b/src/openvpn/misc.h
> @@ -98,7 +98,7 @@ void setenv_counter(struct env_set *es, const char *name, counter_type value);
>  
>  void setenv_int(struct env_set *es, const char *name, int value);
>  
> -void setenv_unsigned(struct env_set *es, const char *name, unsigned int value);
> +void setenv_long_long(struct env_set *es, const char *name, long long value);
>  
>  void setenv_str(struct env_set *es, const char *name, const char *value);
>  
> diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
> index 4545bce1..82a0b9d9 100644
> --- a/src/openvpn/multi.c
> +++ b/src/openvpn/multi.c
> @@ -565,10 +565,7 @@ multi_client_disconnect_setenv(struct multi_context *m,
>      setenv_stats(&mi->context);
>  
>      /* setenv connection duration */
> -    {
> -        const unsigned int duration = (unsigned int) now - mi->created;
> -        setenv_unsigned(mi->context.c2.es, "time_duration", duration);
> -    }
> +    setenv_long_long(mi->context.c2.es, "time_duration", now - mi->created);
>  }
>  
>  static void
> @@ -1769,7 +1766,7 @@ multi_client_connect_setenv(struct multi_context *m,
>      {
>          const char *created_ascii = time_string(mi->created, 0, false, &gc);
>          setenv_str(mi->context.c2.es, "time_ascii", created_ascii);
> -        setenv_unsigned(mi->context.c2.es, "time_unix", (unsigned int)mi->created);
> +        setenv_long_long(mi->context.c2.es, "time_unix", mi->created);
>      }
>  
>      gc_free(&gc);
> diff --git a/src/openvpn/options.c b/src/openvpn/options.c
> index 7aa311aa..641a26e2 100644
> --- a/src/openvpn/options.c
> +++ b/src/openvpn/options.c
> @@ -990,7 +990,7 @@ setenv_settings(struct env_set *es, const struct options *o)
>      setenv_int(es, "verb", o->verbosity);
>      setenv_int(es, "daemon", o->daemon);
>      setenv_int(es, "daemon_log_redirect", o->log);
> -    setenv_unsigned(es, "daemon_start_time", time(NULL));
> +    setenv_long_long(es, "daemon_start_time", time(NULL));
>      setenv_int(es, "daemon_pid", platform_getpid());
>  
>      if (o->connection_list)
> 

Change makes sense and patch looks good.

Acked-by: Steffan Karger <steffan@karger.me>

-Steffan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Gert Doering Nov. 10, 2017, 2:03 p.m. | #2
Your patch has been applied to the master branch.

commit 6c69693adbda2c6abf44b3430afd9ed22bf9e532
Author: Jeremie Courreges-Anglas
Date:   Sun Nov 5 10:46:41 2017 +0100

     Use long long to format time_t-related environment variables

     Signed-off-by: Jeremie Courreges-Anglas <jca@wxcvbn.org>
     Acked-by: Steffan Karger <steffan.karger@fox-it.com>
     Message-Id: <20171105094641.55673-1-jca@wxcvbn.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15750.html
     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/misc.c b/src/openvpn/misc.c
index 8c7f6116..001fe1c4 100644
--- a/src/openvpn/misc.c
+++ b/src/openvpn/misc.c
@@ -553,10 +553,10 @@  setenv_int(struct env_set *es, const char *name, int value)
 }
 
 void
-setenv_unsigned(struct env_set *es, const char *name, unsigned int value)
+setenv_long_long(struct env_set *es, const char *name, long long value)
 {
     char buf[64];
-    openvpn_snprintf(buf, sizeof(buf), "%u", value);
+    openvpn_snprintf(buf, sizeof(buf), "%lld", value);
     setenv_str(es, name, buf);
 }
 
diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h
index eb39ce3f..f6c810a2 100644
--- a/src/openvpn/misc.h
+++ b/src/openvpn/misc.h
@@ -98,7 +98,7 @@  void setenv_counter(struct env_set *es, const char *name, counter_type value);
 
 void setenv_int(struct env_set *es, const char *name, int value);
 
-void setenv_unsigned(struct env_set *es, const char *name, unsigned int value);
+void setenv_long_long(struct env_set *es, const char *name, long long value);
 
 void setenv_str(struct env_set *es, const char *name, const char *value);
 
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 4545bce1..82a0b9d9 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -565,10 +565,7 @@  multi_client_disconnect_setenv(struct multi_context *m,
     setenv_stats(&mi->context);
 
     /* setenv connection duration */
-    {
-        const unsigned int duration = (unsigned int) now - mi->created;
-        setenv_unsigned(mi->context.c2.es, "time_duration", duration);
-    }
+    setenv_long_long(mi->context.c2.es, "time_duration", now - mi->created);
 }
 
 static void
@@ -1769,7 +1766,7 @@  multi_client_connect_setenv(struct multi_context *m,
     {
         const char *created_ascii = time_string(mi->created, 0, false, &gc);
         setenv_str(mi->context.c2.es, "time_ascii", created_ascii);
-        setenv_unsigned(mi->context.c2.es, "time_unix", (unsigned int)mi->created);
+        setenv_long_long(mi->context.c2.es, "time_unix", mi->created);
     }
 
     gc_free(&gc);
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 7aa311aa..641a26e2 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -990,7 +990,7 @@  setenv_settings(struct env_set *es, const struct options *o)
     setenv_int(es, "verb", o->verbosity);
     setenv_int(es, "daemon", o->daemon);
     setenv_int(es, "daemon_log_redirect", o->log);
-    setenv_unsigned(es, "daemon_start_time", time(NULL));
+    setenv_long_long(es, "daemon_start_time", time(NULL));
     setenv_int(es, "daemon_pid", platform_getpid());
 
     if (o->connection_list)