Skip to contentSkip to conversation

tls-crypt: properly cast time_t to uint64_t

PATCH In review Antonio Quartulli 3 participants 3 messages Oct 31, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tls-crypt: properly cast time_t to uint64_t

The exact type of time_t is platform dependent and therefore can't be assumed to be uint64_t all the time.

For example, on 32bit platforms, where time_t is defined as long (32bit), the compiler will generate the following warning, due to the arithmetic used in the macro:

tls_crypt.c:745:29: warning: shift count >= width of type [-Wshift-count-overflow]

Force time_t to be parsed as uint64_t.

---
 src/openvpn/tls_crypt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/tls_crypt.c +1 -1
index d70d0a66..c3ed2b93 100644
@@ -742,7 +742,7 @@ tls_crypt_v2_write_client_key_file(const char *filename,
     }
     else
     {
-        int64_t timestamp = htonll(now);
+        int64_t timestamp = htonll((uint64_t)now);
         ASSERT(buf_write(&metadata, &TLS_CRYPT_METADATA_TYPE_TIMESTAMP, 1));
         ASSERT(buf_write(&metadata, &timestamp, sizeof(timestamp)));
     }
Signature · 1 line
2.19.1
#1 lore raw

Am 31.10.18 um 17:01 schrieb Antonio Quartulli:

Quoted 12 lines

The exact type of time_t is platform dependent and therefore can't be assumed to be uint64_t all the time.

For example, on 32bit platforms, where time_t is defined as long (32bit), the compiler will generate the following warning, due to the arithmetic used in the macro:

tls_crypt.c:745:29: warning: shift count >= width of type [-Wshift-count-overflow]

Force time_t to be parsed as uint64_t.

ACK. Fixes the warning on my Android build and looks correct.

Arne

#2 lore raw
In reply to Antonio Quartulli

Your patch has been applied to the master branch.

commit ddd925bf23bc1b43fda93d2757619a1613cec1ba

Author: Antonio Quartulli
Date:   Thu Nov 1 00:01:24 2018 +0800
     tls-crypt: properly cast time_t to uint64_t

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg17868.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering