Skip to content

Commit

Permalink
Merge pull request #1649 from greenbone/mergify/bp/gvmd-21.04/pr-1644
Browse files Browse the repository at this point in the history
Fix for parse_iso_time_tz error with musl library (backport #1644)
  • Loading branch information
bjoernricks authored Jul 29, 2021
2 parents 134e8fe + 473f2cf commit a75d680
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix memory errors in modify_permission [#1613](https://github.com/greenbone/gvmd/pull/1613)
- Fix sensor connection for performance reports on failure [#1633](https://github.com/greenbone/gvmd/pull/1633)
- Sort the "host" column by IPv4 address if possible [#1637](https://github.com/greenbone/gvmd/pull/1637)
- Fix for parse_iso_time_tz error with musl library [#1644](https://github.com/greenbone/gvmd/pull/1644)

[Unreleased]: https://github.com/greenbone/gvmd/compare/v20.8.2...gvmd-20.08

Expand Down
6 changes: 5 additions & 1 deletion src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -5799,7 +5799,11 @@ manage_scap_update_time ()
if (strptime (content, "%Y%m%d%H%M", &update_time))
{
static char time_string[100];
strftime (time_string, 99, "%FT%T.000%z", &update_time);
#if !defined(__GLIBC__)
strftime (time_string, 99, "%Y-%m-%dT%T.000", &update_time);
#else
strftime (time_string, 99, "%FT%T.000%z", &update_time);
#endif
return time_string;
}
return "";
Expand Down
12 changes: 10 additions & 2 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -26261,7 +26261,11 @@ host_summary_append (GString *host_summary_buffer, const char *host,
struct tm start_tm;

memset (&start_tm, 0, sizeof (struct tm));
if (strptime (start_iso, "%FT%H:%M:%S", &start_tm) == NULL)
#if !defined(__GLIBC__)
if (strptime (start_iso, "%Y-%m-%dT%H:%M:%S", &start_tm) == NULL)
#else
if (strptime (start_iso, "%FT%H:%M:%S", &start_tm) == NULL)
#endif
{
g_warning ("%s: Failed to parse start", __func__);
return;
Expand All @@ -26281,7 +26285,11 @@ host_summary_append (GString *host_summary_buffer, const char *host,
struct tm end_tm;

memset (&end_tm, 0, sizeof (struct tm));
if (strptime (end_iso, "%FT%H:%M:%S", &end_tm) == NULL)
#if !defined(__GLIBC__)
if (strptime (end_iso, "%Y-%m-%dT%H:%M:%S", &end_tm) == NULL)
#else
if (strptime (end_iso, "%FT%H:%M:%S", &end_tm) == NULL)
#endif
{
g_warning ("%s: Failed to parse end", __func__);
return;
Expand Down
31 changes: 25 additions & 6 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,31 @@ parse_iso_time_tz (const char *text_time, const char *fallback_tz)
secs_str && strcmp (secs_str, "")
? secs_str : ":00",
offset_str ? offset_str : "");

if (strptime_with_reset ((char*) cleaned_text_time, "%FT%T%z", &tm))
#if !defined(__GLIBC__)
if (strptime_with_reset ((char*) cleaned_text_time, "%Y-%m-%dT%T", &tm))
#else
if (strptime_with_reset ((char*) cleaned_text_time, "%FT%T%z", &tm))
#endif
{
/* ISO time with numeric offset (e.g. 2020-06-01T01:02:03+04:30) */
tm.tm_sec = tm.tm_sec - tm.tm_gmtoff;
tm.tm_gmtoff = 0;
epoch_time = mktime_with_tz (&tm, "UTC");
}
else if (strptime_with_reset ((char*) cleaned_text_time, "%FT%TZ", &tm))
#if !defined(__GLIBC__)
else if (strptime_with_reset ((char*) cleaned_text_time, "%Y-%m-%dT%T", &tm))
#else
else if (strptime_with_reset ((char*) cleaned_text_time, "%FT%TZ", &tm))
#endif
{
/* ISO time with "Z" for UTC timezone (e.g. 2020-06-01T01:02:03Z) */
epoch_time = mktime_with_tz (&tm, "UTC");
}
else if (strptime_with_reset ((char*) cleaned_text_time, "%FT%T", &tm))
#if !defined(__GLIBC__)
else if (strptime_with_reset ((char*) cleaned_text_time, "%Y-%m-%dT%T", &tm))
#else
else if (strptime_with_reset ((char*) cleaned_text_time, "%FT%T", &tm))
#endif
{
/* ISO time without timezone suffix (e.g. 2020-06-01T01:02:03) */
epoch_time = mktime_with_tz (&tm, fallback_tz ? fallback_tz : "UTC");
Expand Down Expand Up @@ -427,7 +438,11 @@ iso_time_internal (time_t *epoch_time, const char **abbrev)
if (timezone == 0)
#endif
{
if (strftime (time_string, 98, "%FT%TZ", &tm) == 0)
#if !defined(__GLIBC__)
if (strftime (time_string, 98, "%Y-%m-%dT%T", &tm) == 0)
#else
if (strftime (time_string, 98, "%FT%TZ", &tm) == 0)
#endif
return NULL;

if (abbrev)
Expand All @@ -437,7 +452,11 @@ iso_time_internal (time_t *epoch_time, const char **abbrev)
{
int len;

if (strftime (time_string, 98, "%FT%T%z", &tm) == 0)
#if !defined(__GLIBC__)
if (strftime (time_string, 98, "%Y-%m-%dT%T", &tm) == 0)
#else
if (strftime (time_string, 98, "%FT%T%z", &tm) == 0)
#endif
return NULL;

/* Insert the ISO 8601 colon by hand. */
Expand Down

0 comments on commit a75d680

Please sign in to comment.