From 3f7f334c283eb76d8ae17fe00509ec54386671cc Mon Sep 17 00:00:00 2001 From: Antonio Valentino Date: Tue, 8 Nov 2011 18:30:58 +0100 Subject: [PATCH] Improve checks in order to prevent a crash reading (ASAR) L0 products --- src/epr_param.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/epr_param.c b/src/epr_param.c index 0aa13dc..79ee65f 100644 --- a/src/epr_param.c +++ b/src/epr_param.c @@ -148,6 +148,13 @@ int epr_set_dyn_dddb_params(EPR_SProductId* product_id) } field = epr_get_field(product_id->sph_record, "LINE_LENGTH"); + if (field == NULL) { + epr_set_err(e_err_invalid_value, + "epr_set_param: wrong SPH: unable to read LINE_LENGTH"); + epr_free_string(tmp); + return 0; + } + line_length = ((uint*) field->elems)[0]; if (line_length == 0) { epr_set_err(e_err_invalid_value, @@ -155,7 +162,15 @@ int epr_set_dyn_dddb_params(EPR_SProductId* product_id) epr_free_string(tmp); return 0; } + field = epr_get_field(product_id->sph_record, "LINES_PER_TIE_PT"); + if (field == NULL) { + epr_set_err(e_err_invalid_value, + "epr_set_param: wrong SPH: unable to read LINES_PER_TIE_PT"); + epr_free_string(tmp); + return 0; + } + num_tie_points_across = ((uint*) field->elems)[0]; if (num_tie_points_across == 0) { epr_set_err(e_err_invalid_value, @@ -180,6 +195,13 @@ int epr_set_dyn_dddb_params(EPR_SProductId* product_id) else if (strcmp(EPR_ENVISAT_PRODUCT_ASAR, epr_sub_string((char*)product_field->elems, 0, 3)) == 0) { field = epr_get_field(product_id->sph_record, "LINE_LENGTH"); + if (field == NULL) { + epr_set_err(e_err_invalid_value, + "epr_set_param: wrong SPH: unable to read LINE_LENGTH"); + epr_free_string(tmp); + return 0; + } + line_length = ((uint*) field->elems)[0]; if (line_length == 0) { epr_set_err(e_err_invalid_value,