3c3fbd0
From 43b6e31f39edbe7de4f4feeef4d0cf6be093e021 Mon Sep 17 00:00:00 2001
3c3fbd0
From: Jan Kara <jack@suse.cz>
3c3fbd0
Date: Mon, 23 Nov 2020 17:12:27 +0100
3c3fbd0
Subject: [PATCH] quotaio_xfs: Warn when large kernel timestamps cannot be
3c3fbd0
 handled
3c3fbd0
MIME-Version: 1.0
3c3fbd0
Content-Type: text/plain; charset=UTF-8
3c3fbd0
Content-Transfer-Encoding: 8bit
3c3fbd0
3c3fbd0
When time_t is 32-bit, warn if the kernel returns anything that cannot
3c3fbd0
fit in these time stamps. This also fixes a compilation warning that
3c3fbd0
shift exceeds data type size. Similarly when converting data to pass to
3c3fbd0
kernel, just avoid the pointless shift (generating compiler warning)
3c3fbd0
when time_t is 32-bit.
3c3fbd0
3c3fbd0
Reported-by: "Dmitry V. Levin" <ldv@altlinux.org>
3c3fbd0
Signed-off-by: Jan Kara <jack@suse.cz>
3c3fbd0
Signed-off-by: Petr Písař <ppisar@redhat.com>
3c3fbd0
---
3c3fbd0
 configure.ac  | 2 ++
3c3fbd0
 quotaio_xfs.c | 9 +++++++++
3c3fbd0
 2 files changed, 11 insertions(+)
3c3fbd0
3c3fbd0
diff --git a/configure.ac b/configure.ac
3c3fbd0
index 2239b49..296b77a 100644
3c3fbd0
--- a/configure.ac
3c3fbd0
+++ b/configure.ac
3c3fbd0
@@ -82,6 +82,8 @@ AS_IF([test x"$enable_werror" != "xno"], [
3c3fbd0
 ])
3c3fbd0
 AC_SUBST([WARN_CFLAGS])
3c3fbd0
 
3c3fbd0
+AC_CHECK_SIZEOF([time_t], [], [#include <time.h>])
3c3fbd0
+
3c3fbd0
 # =========
3c3fbd0
 # Find ldap
3c3fbd0
 # =========
3c3fbd0
diff --git a/quotaio_xfs.c b/quotaio_xfs.c
3c3fbd0
index 2db1c0c..5abb2c2 100644
3c3fbd0
--- a/quotaio_xfs.c
3c3fbd0
+++ b/quotaio_xfs.c
3c3fbd0
@@ -45,8 +45,13 @@ report:		xfs_report
3c3fbd0
 static inline time_t xfs_kern2utildqblk_ts(const struct xfs_kern_dqblk *k,
3c3fbd0
 		__s32 timer, __s8 timer_hi)
3c3fbd0
 {
3c3fbd0
+#if SIZEOF_TIME_T > 4
3c3fbd0
 	if (k->d_fieldmask & FS_DQ_BIGTIME)
3c3fbd0
 		return (__u32)timer | (__s64)timer_hi << 32;
3c3fbd0
+#else
3c3fbd0
+	if (k->d_fieldmask & FS_DQ_BIGTIME && timer_hi != 0)
3c3fbd0
+		errstr(_("Truncating kernel returned time stamp."));
3c3fbd0
+#endif
3c3fbd0
 	return timer;
3c3fbd0
 }
3c3fbd0
 
3c3fbd0
@@ -54,10 +59,14 @@ static inline void xfs_util2kerndqblk_ts(const struct xfs_kern_dqblk *k,
3c3fbd0
 		__s32 *timer_lo, __s8 *timer_hi, time_t timer)
3c3fbd0
 {
3c3fbd0
 	*timer_lo = timer;
3c3fbd0
+#if SIZEOF_TIME_T > 4
3c3fbd0
 	if (k->d_fieldmask & FS_DQ_BIGTIME)
3c3fbd0
 		*timer_hi = timer >> 32;
3c3fbd0
 	else
3c3fbd0
 		*timer_hi = 0;
3c3fbd0
+#else
3c3fbd0
+	*timer_hi = 0;
3c3fbd0
+#endif
3c3fbd0
 }
3c3fbd0
 
3c3fbd0
 static inline int want_bigtime(time_t timer)
3c3fbd0
-- 
3c3fbd0
2.26.2
3c3fbd0