From patchwork Wed Oct 4 12:47:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremie Courreges-Anglas X-Patchwork-Id: 11 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director3.mail.ord1d.rsapps.net ([172.30.157.9]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id ecrBLV141VnKOgAAgoeIoA for ; Wed, 04 Oct 2017 20:10:05 -0400 Received: from director8.mail.ord1c.rsapps.net ([172.28.130.196]) by director3.mail.ord1d.rsapps.net (Dovecot) with LMTP id ddMtFXKq1FlBNAAAkXNnRw ; Wed, 04 Oct 2017 20:10:05 -0400 Received: from smtp59.gate.ord1a ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by director8.mail.ord1c.rsapps.net (Dovecot) with LMTP id ACbsD1B31VkyOQAAPBwpBw ; Wed, 04 Oct 2017 20:10:05 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-MessageSniffer-Scan-Result: 0 X-MessageSniffer-Rules: 0-298-1145-1348-w 0-298-1145-1712-w 0-298-0-10975-f X-CMAE-Scan-Result: 0 X-CNFS-Analysis: v=2.2 cv=SPYAb6nH c=1 sm=1 tr=0 a=Q8DxjiC8O3VT/NpP1XjEZQ==:117 a=Q8DxjiC8O3VT/NpP1XjEZQ==:17 a=02M-m0pO-4AA:10 a=WiVod9pSvdkA:10 a=3tcz3bTJAAAA:8 a=Mjd_eUnMJTxOXZ4udRYA:9 a=JKa-Rr5HnN4A:10 a=i6EfmcryGl0A:10 a=LLj1TIjvAAAA:8 a=8KXOIYFTGK8IPxalEMAA:9 a=cHQdju6GVAdPPvx_KJ0A:9 a=9sSjY8p1AAAA:8 a=P_JWiMecAAAA:8 a=Rl0w98V0Q82ZLrlrn6IA:9 a=CjuIK1q_8ugA:10 a=-FEs8UIgK8oA:10 a=NWVoK91CQyQA:10 a=FP58Ms26AAAA:8 a=-jli9x3zI_mR8X_O0lMA:9 a=4EbjBm0RLgFgoQzmu6QD:22 a=6swFX36t3RvqdHmuLAOK:22 a=ub54wNWiXv_DzeFsgEJW:22 a=D0-HAvA3Hk9NMREbgwuX:22 X-Orig-To: justin@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp59.gate.ord1a.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=wxcvbn.org X-Classification-ID: 8a088f58-a961-11e7-b228-842b2b4126a2-1-1 Received: from [216.34.181.88] ([216.34.181.88:54330] helo=lists.sourceforge.net) by smtp59.gate.ord1a.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 9A/01-12051-D5875D95; Wed, 04 Oct 2017 20:10:05 -0400 Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1dztjS-0000Ej-CP; Thu, 05 Oct 2017 00:09:42 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) (envelope-from ) id 1dztjR-0000Ed-Az for openvpn-devel@lists.sourceforge.net; Thu, 05 Oct 2017 00:09:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From; bh=gRUv5gdYJzdQt9kL/RXqdb8zqEu3XKw0gzlK/YFtEF4=; b=b1fKK8LumdGrgUWsLo+lG0KS7LrTw+5wmHc9xJikagLz4PH6Dp66aK05g/aHbVg2o3BWhZnUeGmpiuXmrSC/N+RnYevG3Op3LTwQ6Ef52GAFPVTaNQRQX3USllUy5NVu4omxzuQpGGg49+CeVKRzGCWrGwU6+SwvHy6WQqcwdmA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From; bh=gRUv5gdYJzdQt9kL/RXqdb8zqEu3XKw0gzlK/YFtEF4=; b=MeL2QeUzVU6uGLw4gLLYy7JcHKEzlStjDJSUWSx7IgnGm3exeJ1q8BhEPm/MndiHHnMB1izMIF16y2bHE0vuWlWVlQWFUVpQm7dZYlIAcdkMw13GqKFzrf0brtfWF1l6qDuFlQ5D0GJq4dHJH+0iDAzK0ntAbBeljdCXCGfKc1w=; Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of wxcvbn.org designates 91.216.110.36 as permitted sender) client-ip=91.216.110.36; envelope-from=jca@wxcvbn.org; helo=chomsky.autogeree.net; Received: from chomsky.autogeree.net ([91.216.110.36]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dztjN-0000ev-LY for openvpn-devel@lists.sourceforge.net; Thu, 05 Oct 2017 00:09:41 +0000 Received: from ritchie.wxcvbn.org (localhost [127.0.0.1]) by wxcvbn.org (8.16.0.21/8.15.2) with ESMTP id v94NlInd066190 for ; Thu, 5 Oct 2017 01:47:18 +0200 (CEST) Received: (from jca@localhost) by ritchie.wxcvbn.org (8.16.0.21/8.16.0.21/Submit) id v94NlH4c085221; Thu, 5 Oct 2017 01:47:17 +0200 (CEST) From: Jeremie Courreges-Anglas To: openvpn-devel@lists.sourceforge.net Mail-Followup-To: openvpn-devel@lists.sourceforge.net Date: Thu, 05 Oct 2017 01:47:17 +0200 Message-ID: <87fuaymq62.fsf@ritchie.wxcvbn.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (berkeley-unix) MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1dztjN-0000ev-LY Subject: [Openvpn-devel] [patch] Fix time_t printing X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox When building openvpn-2.4.4 on OpenBSD, I noticed the following warning: --8<-- cc -DHAVE_CONFIG_H -I. -I/usr/ports/pobj/openvpn-2.4.4/openvpn-2.4.4/src/openvpn -I../.. -I../../include -I/usr/ports/pobj/openvpn-2.4.4/openvpn-2.4.4/include -I/usr/ports/pobj/openvpn-2.4.4/openvpn-2.4.4/src/compat -I/usr/local/include -I/usr/local/include -DPLUGIN_LIBDIR=\"/usr/local/lib/openvpn/plugins\" -O2 -pipe -std=c99 -MT error.o -MD -MP -MF .deps/error.Tpo -c -o error.o /usr/ports/pobj/openvpn-2.4.4/openvpn-2.4.4/src/openvpn/error.c /usr/ports/pobj/openvpn-2.4.4/openvpn-2.4.4/src/openvpn/error.c:346:25: warning: format specifies type 'unsigned long' but the argument has type 'time_t' (aka 'long long') [-Wformat] tv.tv_sec, ^~~~~~~~~ 1 warning generated. mv -f .deps/error.Tpo .deps/error.Po -->8-- OpenBSD uses long long for time_t on all architectures, 32 or 64 bits, in order to cope with dates beyond 2038. This is also the case on NetBSD and Linux x32. The warning is not innocuous, as a mismatch between the format and the type of parameters passed to variadic functions can result in nasty problems (crashes, etc). For example, the code below crashes on OpenBSD/arm (32 bits long). --8<-- #include #include int main(void) { time_t t; time(&t); printf("%ld %s\n", t, "foobar"); return 0; } -->8-- The diff below fixes the potential issue and the warning. The method used is a cast to (long long), a method successfully used since OpenBSD switched to a 64 bits time_t. More data at https://www.openbsd.org/papers/eurobsdcon_2013_time_t/mgp00029.html openvpn already uses long long in a few places. Note that I did not audit the whole openvpn tree for other possible time_t problems, but I can't spot similar warnings in the build logs. Signed-off-by: Jeremie Courreges-Anglas Signed-off-by: Jeremie Courreges-Anglas Acked-by: Steffan Karger From d620431f661375d3564b60f110d1f69575ac78d7 Mon Sep 17 00:00:00 2001 From: Jeremie Courreges-Anglas Date: Thu, 5 Oct 2017 01:43:33 +0200 Subject: [PATCH] Cast time_t to long double in order to print it. The underlying type of time_t can be anything from unsigned 32 bits to signed 64 bits to float. To reliably print it, better cast it to "long long", which is at least 64 bits wide and can represent values beyond 2038. Printing as a "long" could cause problems on ILP32 systems using a 64 bits time_t (eg OpenBSD/armv7). Signed-off-by: Jeremie Courreges-Anglas --- src/openvpn/error.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openvpn/error.c b/src/openvpn/error.c index 04bf0da5..7b46c5ec 100644 --- a/src/openvpn/error.c +++ b/src/openvpn/error.c @@ -342,8 +342,8 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist) struct timeval tv; gettimeofday(&tv, NULL); - fprintf(fp, "%lu.%06lu %x %s%s%s%s", - tv.tv_sec, + fprintf(fp, "%lld.%06lu %x %s%s%s%s", + (long long)tv.tv_sec, (unsigned long)tv.tv_usec, flags, prefix, -- 2.14.2