From 22a8bf56040c113478c6cbf03ac8c5b79cdb7961 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 20 May 2022 09:10:59 +0200 Subject: [PATCH 1/4] Validate timestamp --- src/as-validator-issue-tag.h | 6 ++++++ src/as-validator.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/as-validator-issue-tag.h b/src/as-validator-issue-tag.h index 28cb9e88..fbfb2647 100644 --- a/src/as-validator-issue-tag.h +++ b/src/as-validator-issue-tag.h @@ -753,6 +753,12 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = { N_("The release is missing either the `date` (preferred) or the `timestamp` property."), }, + { "release-timestamp-invalid", + AS_ISSUE_SEVERITY_ERROR, + /* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */ + N_("The release timestamp is invalid."), + }, + { "artifact-type-invalid", AS_ISSUE_SEVERITY_ERROR, /* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */ diff --git a/src/as-validator.c b/src/as-validator.c index 3a53864f..412c9388 100644 --- a/src/as-validator.c +++ b/src/as-validator.c @@ -1689,6 +1689,11 @@ as_validator_check_release (AsValidator *validator, xmlNode *node, AsFormatStyle /* Neither timestamp, nor date property exists */ if (timestamp == NULL) as_validator_add_issue (validator, node, "release-time-missing", "date"); + else { + if (atoi(timestamp) <= 3000) { + as_validator_add_issue (validator, node, "release-timestamp-invalid", "timestamp"); + } + } } prop = as_xml_get_prop_value (node, "date_eol"); if (prop != NULL) { From 69f43cbc97d8a96709143a9ba45a7a7704d05a44 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 20 May 2022 16:17:17 +0200 Subject: [PATCH 2/4] Use g_ascii_strtoll() --- src/as-validator.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/as-validator.c b/src/as-validator.c index 412c9388..17a454d7 100644 --- a/src/as-validator.c +++ b/src/as-validator.c @@ -1690,7 +1690,8 @@ as_validator_check_release (AsValidator *validator, xmlNode *node, AsFormatStyle if (timestamp == NULL) as_validator_add_issue (validator, node, "release-time-missing", "date"); else { - if (atoi(timestamp) <= 3000) { + /* check if the timestamp is both a number and higher than 3000. The 3000 is used to check, that it is not a year */ + if (g_ascii_strtoll (timestamp, NULL, 10) < 3000) { as_validator_add_issue (validator, node, "release-timestamp-invalid", "timestamp"); } } From c4ed6ff919ac9b97db0f42d4a957130e3f3aa631 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 20 May 2022 16:58:58 +0200 Subject: [PATCH 3/4] Resolve nitpicks --- src/as-validator-issue-tag.h | 1 - src/as-validator.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/as-validator-issue-tag.h b/src/as-validator-issue-tag.h index fbfb2647..f48cd1dd 100644 --- a/src/as-validator-issue-tag.h +++ b/src/as-validator-issue-tag.h @@ -755,7 +755,6 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = { { "release-timestamp-invalid", AS_ISSUE_SEVERITY_ERROR, - /* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */ N_("The release timestamp is invalid."), }, diff --git a/src/as-validator.c b/src/as-validator.c index 17a454d7..07ae5afd 100644 --- a/src/as-validator.c +++ b/src/as-validator.c @@ -1690,9 +1690,9 @@ as_validator_check_release (AsValidator *validator, xmlNode *node, AsFormatStyle if (timestamp == NULL) as_validator_add_issue (validator, node, "release-time-missing", "date"); else { - /* check if the timestamp is both a number and higher than 3000. The 3000 is used to check, that it is not a year */ if (g_ascii_strtoll (timestamp, NULL, 10) < 3000) { - as_validator_add_issue (validator, node, "release-timestamp-invalid", "timestamp"); + /* check if the timestamp is both a number and higher than 3000. The 3000 is used to check that it is not a year */ + as_validator_add_issue (validator, node, "release-timestamp-invalid", timestamp); } } } From bd53bf5c6034ad712777ff202c3954cd0d35cdd8 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Sat, 21 May 2022 14:14:20 +0200 Subject: [PATCH 4/4] Move comment into if condition --- src/as-validator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/as-validator.c b/src/as-validator.c index 07ae5afd..5a3d0d1f 100644 --- a/src/as-validator.c +++ b/src/as-validator.c @@ -1686,8 +1686,8 @@ as_validator_check_release (AsValidator *validator, xmlNode *node, AsFormatStyle g_free (prop); } else { g_autofree gchar *timestamp = as_xml_get_prop_value (node, "timestamp"); - /* Neither timestamp, nor date property exists */ if (timestamp == NULL) + /* Neither timestamp, nor date property exists */ as_validator_add_issue (validator, node, "release-time-missing", "date"); else { if (g_ascii_strtoll (timestamp, NULL, 10) < 3000) {