Skip to content

Commit ac679a5

Browse files
authored
Merge pull request #516 from E3SM-Project/dqwu/check_read_filename_length
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.
2 parents 48784fd + 5f65dc8 commit ac679a5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/clib/pioc_support.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ int PIOc_createfile_int(int iosysid, int *ncidp, const int *iotype, const char *
26642664
if (!ncidp || !iotype || !filename || strlen(filename) > PIO_MAX_NAME)
26652665
{
26662666
return pio_err(ios, NULL, PIO_EINVAL, __FILE__, __LINE__,
2667-
"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);
2667+
"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);
26682668
}
26692669

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

34253425
/* User must provide valid input for these parameters. */
3426-
if (!ncidp || !iotype || !filename)
3426+
if (!ncidp || !iotype || !filename || strlen(filename) > PIO_MAX_NAME)
34273427
{
34283428
return pio_err(ios, NULL, PIO_EINVAL, __FILE__, __LINE__,
3429-
"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));
3429+
"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);
34303430
}
34313431

34323432
/* A valid iotype must be specified. */

0 commit comments

Comments
 (0)