-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: fix timestamp validation #4356
base: devel
Are you sure you want to change the base?
Conversation
cli/src/cli-cmd-parser.c's config_parse was calling strftime with a struct tm that may have tm_year that is out of range for strftime, yielding unspecified and/or undefined behavior. Fix this by using mktime instead of strftime, as mktime's behavior is well-defined for out-of-range values. This also fixes a portability issue with strftime %s and time zones. Fixes: gluster#4355 Signed-off-by: Paul Eggert <[email protected]>
Can one of the admins verify this patch? |
2 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
CLANG-FORMAT FAILURE: index e39f60ed8..ef12ab894 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -2594,7 +2594,7 @@ config_parse(const char **words, int wordcount, dict_t *dict, unsigned cmdi,
memset(&checkpoint_time, 0, sizeof(struct tm));
ret_chkpt = strptime(append_str, "%Y-%m-%d %H:%M:%S",
&checkpoint_time);
- checkpoint_sec = mktime (&checkpoint_time);
+ checkpoint_sec = mktime(&checkpoint_time);
if (ret_chkpt == NULL || *ret_chkpt != '\0' ||
checkpoint_time.tm_mday == 0) {
@@ -2610,7 +2610,7 @@ config_parse(const char **words, int wordcount, dict_t *dict, unsigned cmdi,
ret = -1;
goto out;
}
- snprintf(append_str, 300, "%lld", (long long) checkpoint_sec);
+ snprintf(append_str, 300, "%lld", (long long)checkpoint_sec);
}
ret = dict_set_dynstr(dict, "op_value", append_str); |
Adjust patch to pass clang-format. Fixes: gluster#4355 Signed-off-by: Paul Eggert <[email protected]>
Don't tell mktime that standard time is in effect. This fixes a bug where the timestamp is off by an hour when daylight saving time is in effect. (The issue is also present in the devel branch, which uses strftime %s and which therefore has the same bug.)
I found an extra bug in the code while re-reviewing my patch: there's an off-by-an-hour bug when daylight saving is in effect. This bug is also present in the original unmodified code in the devel branch, as strftime %s has the same issue with tm_isdst that mktime does. I pushed commit 444a949 to fix this extra bug. |
/run regression |
1 test(s) failed 0 test(s) generated core 1 test(s) needed retry |
cli/src/cli-cmd-parser.c's config_parse was calling strftime with a struct tm that may have tm_year that is out of range for strftime, yielding unspecified and/or undefined behavior. Fix this by using mktime instead of strftime, as mktime's behavior is well-defined for out-of-range values. This also fixes a portability issue with strftime %s and time zones.
Fixes: #4355