From d494d88c95516a87aaa16d5a915d92b5c213eafa Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 22 Mar 2022 17:25:11 -0400 Subject: datetime: Don't forget to copy NUL chars to buffer --- diff --git a/src/datetime.c b/src/datetime.c index ffc3329..08ed9a6 100644 --- a/src/datetime.c +++ b/src/datetime.c @@ -142,7 +142,7 @@ datetime_parse(struct tm *now_tm, const char *input, time_t *arg_sec) sec = *arg_sec; /* GCC is dumb. */ got = false; for (t = 0; t < sizeof(FORMATS_TIME) / sizeof(FORMATS_TIME[0]) ; ++t) { - memcpy(fmt_buf, FORMATS_TIME[t], time_fmt_len); + memcpy(fmt_buf, FORMATS_TIME[t], time_fmt_len + 1); _datetime_reset_tm(&arg_tm); end = strptime(input, fmt_buf, &arg_tm); if (end != NULL && *end == '\0') { @@ -159,11 +159,11 @@ datetime_parse(struct tm *now_tm, const char *input, time_t *arg_sec) if (FORMATS_DATE[d][0] == '\0') { break; } - memcpy(fmt_buf, FORMATS_DATE[d], date_fmt_len); + memcpy(fmt_buf, FORMATS_DATE[d], date_fmt_len + 1); for (t = 0; t < sizeof(FORMATS_TIME) / sizeof(FORMATS_TIME[0]); ++t) { memcpy(fmt_buf + date_fmt_len, FORMATS_TIME[t], - time_fmt_len); + time_fmt_len + 1); _datetime_reset_tm(&arg_tm); end = strptime(input, fmt_buf, &arg_tm); if (end != NULL && *end == '\0') { @@ -178,14 +178,14 @@ datetime_parse(struct tm *now_tm, const char *input, time_t *arg_sec) } } for (t = 0; t < sizeof(FORMATS_TIME) / sizeof(FORMATS_TIME[0]); ++t) { - memcpy(fmt_buf, FORMATS_TIME[t], time_fmt_len); + memcpy(fmt_buf, FORMATS_TIME[t], time_fmt_len + 1); for (d = 0; d < sizeof(FORMATS_DATE) / sizeof(FORMATS_DATE[0]); ++d) { if (FORMATS_DATE[d][0] == '\0') { break; } memcpy(fmt_buf + time_fmt_len, FORMATS_DATE[d], - date_fmt_len); + date_fmt_len + 1); _datetime_reset_tm(&arg_tm); end = strptime(input, fmt_buf, &arg_tm); if (end != NULL && *end == '\0') { @@ -200,7 +200,7 @@ datetime_parse(struct tm *now_tm, const char *input, time_t *arg_sec) } } for (d = 0; d < sizeof(FORMATS_MISC) / sizeof(FORMATS_MISC[0]) ; ++d) { - memcpy(fmt_buf, FORMATS_MISC[d], misc_fmt_len); + memcpy(fmt_buf, FORMATS_MISC[d], misc_fmt_len + 1); _datetime_reset_tm(&arg_tm); end = strptime(input, fmt_buf, &arg_tm); if (end != NULL && *end == '\0') { -- cgit v0.9.1