Checks for descriptor string lengths

This commit is contained in:
Shahram Najm 2020-07-29 11:44:34 +01:00
parent 5b0f7ba936
commit 89af2ae8dd
1 changed files with 11 additions and 5 deletions

View File

@ -343,8 +343,6 @@ static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v)
int ret = 0;
char** list = 0;
char code[7] = { 0 };
const size_t maxlen_shortName = sizeof(v->shortName);
const size_t maxlen_units = sizeof(v->units);
grib_trie* table = load_bufr_elements_table(a, &ret);
if (ret)
@ -356,11 +354,19 @@ static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v)
if (!list)
return GRIB_NOT_FOUND;
DebugAssert( strlen(list[1]) < maxlen_shortName );
#ifdef DEBUG
{
/* ECC-1137: check descriptor key name and unit lengths */
const size_t maxlen_shortName = sizeof(v->shortName);
const size_t maxlen_units = sizeof(v->units);
Assert( strlen(list[1]) < maxlen_shortName );
Assert( strlen(list[4]) < maxlen_units );
}
#endif
strcpy(v->shortName, list[1]);
v->type = convert_type(list[2]);
/* v->name=grib_context_strdup(c,list[3]); See ECC-489 */
DebugAssert( strlen(list[4]) < maxlen_units );
strcpy(v->units, list[4]);
/* ECC-985: Scale and reference are often 0 so we can reduce calls to atol */