Skip to content
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

Fix for parse_iso_time_tz error with musl library #1644

Merged
merged 3 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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 @@ -5782,7 +5782,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 @@ -26277,7 +26277,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 @@ -26297,7 +26301,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 @@ -366,20 +366,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 @@ -429,7 +440,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 @@ -439,7 +454,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