Skip to content

Commit

Permalink
fix: set the update module when reading header-info
Browse files Browse the repository at this point in the history
Setting the update module when preparing the data is too late - and it
can lead to unexpected behaviour in the state machine if the artifact
doesn't contain files.

Changelog: None
Ticket: MEN-7804

Signed-off-by: Daniel Skinstad Drabitzius <[email protected]>
  • Loading branch information
danielskinstad committed Feb 3, 2025
1 parent 450486a commit 2cbec52
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions core/src/mender-artifact.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ static mender_err_t artifact_read_version(mender_artifact_ctx_t *ctx);
/**
* @brief Read header-info file of the artifact
* @param ctx Artifact context
* @param dl_data Download data for the artifact
* @return MENDER_DONE if the data have been parsed and payloads retrieved, MENDER_OK if there is not enough data to parse, error code if an error occurred
*/
static mender_err_t artifact_read_header_info(mender_artifact_ctx_t *ctx);
static mender_err_t artifact_read_header_info(mender_artifact_ctx_t *ctx, mender_artifact_download_data_t *dl_data);

#ifdef CONFIG_MENDER_FULL_PARSE_ARTIFACT
/**
Expand Down Expand Up @@ -423,7 +424,7 @@ mender_artifact_process_data(mender_artifact_ctx_t *ctx, void *input_data, size_
} else if (StringEqual(ctx->file.name, "header.tar/header-info")) {

/* Read header-info file */
ret = artifact_read_header_info(ctx);
ret = artifact_read_header_info(ctx, dl_data);

} else if ((true == mender_utils_strbeginswith(ctx->file.name, "header.tar/headers"))
&& (true == mender_utils_strendswith(ctx->file.name, "meta-data"))) {
Expand Down Expand Up @@ -838,7 +839,7 @@ artifact_parse_provides_depends(cJSON *json_provides_depends, mender_key_value_l
#endif

static mender_err_t
artifact_read_header_info(mender_artifact_ctx_t *ctx) {
artifact_read_header_info(mender_artifact_ctx_t *ctx, mender_artifact_download_data_t *dl_data) {

assert(NULL != ctx);
cJSON *object = NULL;
Expand Down Expand Up @@ -874,6 +875,21 @@ artifact_read_header_info(mender_artifact_ctx_t *ctx) {
ret = MENDER_FAIL;
goto END;
}
const char *payload_type = ctx->payloads.values[index].type;
/* Choose update module */
dl_data->update_module = mender_update_module_get(payload_type);
if (NULL == dl_data->update_module) {
/* Content is not supported by the mender-mcu-client */
mender_log_error("Unable to handle artifact type '%s'", payload_type);
ret = MENDER_FAIL;
goto END;
}
/* Add the payload type to deployment data */
if (MENDER_OK != mender_deployment_data_add_payload_type(dl_data->deployment, payload_type)) {
/* Error already logged */
ret = MENDER_FAIL;
goto END;
}
} else {
mender_log_error("Invalid header-info file");
ret = MENDER_FAIL;
Expand Down Expand Up @@ -1184,20 +1200,6 @@ artifact_read_data_prepare(mender_artifact_ctx_t *ctx, mender_artifact_download_

const char *payload_type = ctx->payloads.values[index].type;

/* Choose update module */
dl_data->update_module = mender_update_module_get(payload_type);
if (NULL == dl_data->update_module) {
/* Content is not supported by the mender-mcu-client */
mender_log_error("Unable to handle artifact type '%s'", payload_type);
return MENDER_FAIL;
}

/* Add the payload type to deployment data */
if (MENDER_OK != mender_deployment_data_add_payload_type(dl_data->deployment, payload_type)) {
/* Error already logged */
return MENDER_FAIL;
}

/* Retrieve ID and artifact name */
if (MENDER_OK != mender_deployment_data_get_id(dl_data->deployment, &(mdata_cache->deployment_id))) {
mender_log_error("Unable to get ID from the deployment data");
Expand Down

0 comments on commit 2cbec52

Please sign in to comment.