Mitigating strncpy truncation

This commit is contained in:
Shahram Najm 2023-03-03 13:18:42 +00:00
parent 46033cdd2b
commit 5c4867198e
2 changed files with 5 additions and 1 deletions

View File

@ -168,7 +168,10 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename)
int err = 0;
err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1);
if (err) strncpy(fname, self->tablename, 1023);
if (err) {
strncpy(fname, self->tablename, sizeof(fname)-1);
fname[sizeof(fname)-1] = '\0';
}
if ((filename = grib_context_full_defs_path(a->context, fname)) == NULL) {
grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot open flag table %s", filename);

View File

@ -643,6 +643,7 @@ static int init_definition_files_dir(grib_context* c)
/* Note: strtok_r modifies its first argument so we copy */
strncpy(path, c->grib_definition_files_path, ECC_PATH_MAXLEN-1);
path[ ECC_PATH_MAXLEN - 1 ] = '\0';
GRIB_MUTEX_INIT_ONCE(&once, &init);
GRIB_MUTEX_LOCK(&mutex_c);