changeset 1068:5306db73b02f v4.8

utils: clear struct tm before calling strptime Some strptime implementations clear the struct tm while others do not. Since we want zeros for everything other than the year, month, day, hour, and minute, we need to explicitly memset the struct. This wasn't noticed before since illumos libc falls into the category of zeroes-tm-for-you implementations. On systems that do not zero struct tm automatically, various random values end up in tm_sec which causes the subsequent mktime to return a value that doesn't represent the passed in string's meaning. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Tue, 23 Feb 2021 18:17:40 +0000
parents 824259d52d7e
children c4521645c612
files utils.c
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/utils.c	Fri Dec 04 14:10:15 2020 -0500
+++ b/utils.c	Tue Feb 23 18:17:40 2021 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2011-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -149,6 +149,9 @@
 	if (!str)
 		return 0;
 
+	/* some implementations of strptime don't reset values not parsed */
+	memset(&tm, 0, sizeof(struct tm));
+
 	strptime(str, "%Y-%m-%d %H:%M", &tm);
 
 	return mktime(&tm);