Skip to content

Commit

Permalink
Merge pull request #516 from E3SM-Project/dqwu/check_read_filename_le…
Browse files Browse the repository at this point in the history
…ngth

In the openfile function, include a check to ensure that the
length of the input file name, including the complete path,
does not exceed the limit defined by PIO_MAX_NAME.

Exceeding this limit could cause failures in low-level NetCDF
or PnetCDF library calls.
  • Loading branch information
dqwu authored May 26, 2023
2 parents 48784fd + 5f65dc8 commit ac679a5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ int PIOc_createfile_int(int iosysid, int *ncidp, const int *iotype, const char *
if (!ncidp || !iotype || !filename || strlen(filename) > PIO_MAX_NAME)
{
return pio_err(ios, NULL, PIO_EINVAL, __FILE__, __LINE__,
"Creating file failed. Invalid arguments provided, ncidp is %s (expected not NULL), iotype is %s (expected not NULL), filename is %s (expected not NULL), filename length = %lld (expected <= %d)", PIO_IS_NULL(ncidp), PIO_IS_NULL(iotype), PIO_IS_NULL(filename), (filename) ? ((unsigned long long )strlen(filename)) : 0, (int )PIO_MAX_NAME);
"Creating file (%s) failed. Invalid arguments provided, ncidp is %s (expected not NULL), iotype is %s (expected not NULL), filename is %s (expected not NULL), filename length = %lld (expected <= %d)", (filename) ? filename : "UNKNOWN", PIO_IS_NULL(ncidp), PIO_IS_NULL(iotype), PIO_IS_NULL(filename), (filename) ? ((unsigned long long )strlen(filename)) : 0, (int )PIO_MAX_NAME);
}

/* A valid iotype must be specified. */
Expand Down Expand Up @@ -3423,10 +3423,10 @@ int PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filena
}

/* User must provide valid input for these parameters. */
if (!ncidp || !iotype || !filename)
if (!ncidp || !iotype || !filename || strlen(filename) > PIO_MAX_NAME)
{
return pio_err(ios, NULL, PIO_EINVAL, __FILE__, __LINE__,
"Opening file (%s) failed. Invalid arguments provided. ncidp is %s (expected not NULL), iotype is %s (expected not NULL), filename is %s (expected not NULL)", (filename) ? filename : "UNKNOWN", PIO_IS_NULL(ncidp), PIO_IS_NULL(iotype), PIO_IS_NULL(filename));
"Opening file (%s) failed. Invalid arguments provided. ncidp is %s (expected not NULL), iotype is %s (expected not NULL), filename is %s (expected not NULL), filename length = %lld (expected <= %d)", (filename) ? filename : "UNKNOWN", PIO_IS_NULL(ncidp), PIO_IS_NULL(iotype), PIO_IS_NULL(filename), (filename) ? ((unsigned long long )strlen(filename)) : 0, (int )PIO_MAX_NAME);
}

/* A valid iotype must be specified. */
Expand Down

0 comments on commit ac679a5

Please sign in to comment.