From a4987b4312616bda15ea04bee21218795b45911a Mon Sep 17 00:00:00 2001 From: Daniel Skinstad Drabitzius Date: Mon, 30 Sep 2024 11:38:35 +0200 Subject: [PATCH 1/2] chore: explicit error for compressed Artifacts Ticket: MEN-7528 Signed-off-by: Daniel Skinstad Drabitzius --- core/src/mender-artifact.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/src/mender-artifact.c b/core/src/mender-artifact.c index c2f8a9a5..ceb6c0f6 100644 --- a/core/src/mender-artifact.c +++ b/core/src/mender-artifact.c @@ -179,6 +179,20 @@ mender_artifact_get_ctx(mender_artifact_ctx_t **ctx) { return MENDER_OK; } +static bool +is_compressed(const char *filename) { + + static const char *compression_suffixes[] = { ".gz", ".xz", ".zst", NULL }; + + for (size_t i = 0; NULL != compression_suffixes[i]; i++) { + if (mender_utils_strendwith(filename, compression_suffixes[i])) { + return true; + } + } + + return false; +} + mender_err_t mender_artifact_process_data(mender_artifact_ctx_t *ctx, void *input_data, @@ -204,6 +218,12 @@ mender_artifact_process_data(mender_artifact_ctx_t *ctx, /* Parse data */ do { + /* We do not support compressed artifacts */ + if (is_compressed(ctx->file.name)) { + mender_log_error("Artifact compression is not supported"); + return MENDER_FAIL; + } + /* Treatment depending of the stream state */ if (MENDER_ARTIFACT_STREAM_STATE_PARSING_HEADER == ctx->stream_state) { From 1f0ef872918514d78a4e27307db84cf346413123 Mon Sep 17 00:00:00 2001 From: Daniel Skinstad Drabitzius Date: Mon, 30 Sep 2024 11:38:36 +0200 Subject: [PATCH 2/2] chore: ensure `size` is not 0 Avoids division by zero errors if you're e.g. using a really small dummy artifact Ticket: None Signed-off-by: Daniel Skinstad Drabitzius --- core/src/mender-client.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/src/mender-client.c b/core/src/mender-client.c index 0139e09f..ed97f07d 100644 --- a/core/src/mender-client.c +++ b/core/src/mender-client.c @@ -1170,15 +1170,18 @@ mender_client_download_artifact_callback(char *type, cJSON *meta_data, char *fil mender_err_t ret = MENDER_FAIL; #if CONFIG_MENDER_LOG_LEVEL >= MENDER_LOG_LEVEL_INF - static size_t download_progress = 0; - /* New update */ - if (0 == index) { - download_progress = 0; - } - /* Update every 10% */ - if (((index * 10) / size) > download_progress) { - download_progress = (index * 10) / size; - mender_log_info("Downloading '%s' %zu0%%... [%zu/%zu]", type, download_progress, index, size); + if (size > 0) { + static size_t download_progress = 0; + /* New update */ + if (0 == index) { + download_progress = 0; + } + + /* Update every 10% */ + if (((index * 10) / size) > download_progress) { + download_progress = (index * 10) / size; + mender_log_info("Downloading '%s' %zu0%%... [%zu/%zu]", type, download_progress, index, size); + } } #endif