Recent Linux kernels have an issue where time() has a lower
granularity than the stat st_mtime of a file. This can result in
time() being earlier than the mtime of a file just modified.
See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1144613
Since the function previously had no error case, use "time(NULL) + 1"
as a fallback behavior in case stat fails or (for some strange reason)
it's called for a receive-mode attachment.
Thanks to Vincent Lefèvre for reporting the issue and working on
finding out the source of the bug. Thanks also to the other
contributors in the thread who helped with reproducing and diagnosing
the problem: Ian Collier, Reed Underwood, and Steffen Nurpmeso.
---
This patch would be to apply to the stable branch for a 2.4.2 release
I'll try to get out in the next week.
sendlib.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/sendlib.c b/sendlib.c
index 150bc72d..b0d60ad3 100644
--- a/sendlib.c
+++ b/sendlib.c
@@ -1284,7 +1284,20 @@ static void mutt_set_encoding(BODY *b, CONTENT *info)
void mutt_stamp_attachment(BODY *a)
{
- a->stamp = time(NULL);
+ struct stat sb;
+
+ if (a->filename && stat(a->filename, &sb) == 0)
+ a->stamp = sb.st_mtime;
+ else
+ {
+ /* Recent Linux kernels have an issue where time() has a lower
+ * granularity than the stat st_mtime of a file. This can result in
+ * time() being earlier than the mtime of a file just modified.
+ * See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1144613
+ * As an error fallback case, add 1 to work around the behavior.
+ */
+ a->stamp = time(NULL) + 1;
+ }
}
/* Get a body's character set */
--
2.55.0