fixed handling of NULL name in nc_open

This commit is contained in:
Ed Hartnett 2019-06-30 04:56:24 -06:00
parent ec752f3f15
commit 41cef20d1a
3 changed files with 29 additions and 19 deletions

View File

@ -1981,6 +1981,10 @@ NC_open(const char *path0, int omode, int basepe, size_t *chunksizehintp,
if(stat) return stat;
}
/* Check inputs. */
if (!path0)
return NC_EINVAL;
/* Capture the inmemory related flags */
mmap = ((omode & NC_MMAP) == NC_MMAP);
diskless = ((omode & NC_DISKLESS) == NC_DISKLESS);

View File

@ -98,32 +98,30 @@ endif
# The .c files that are generated with m4 are already distributed, but
# we also include the original m4 files, plus test scripts data.
EXTRA_DIST = test_get.m4 test_put.m4 run_diskless.sh run_diskless2.sh \
run_diskless5.sh run_mmap.sh run_pnetcdf_test.sh test_read.m4 \
test_write.m4 ref_tst_diskless2.cdl tst_diskless5.cdl \
ref_tst_diskless3_create.cdl ref_tst_diskless3_open.cdl \
run_inmemory.sh run_mmap.sh \
f03tst_open_mem.nc \
test_byterange.sh ref_tst_http_nc3.cdl ref_tst_http_nc4.cdl \
CMakeLists.txt
EXTRA_DIST = test_get.m4 test_put.m4 run_diskless.sh run_diskless2.sh \
run_diskless5.sh run_mmap.sh run_pnetcdf_test.sh test_read.m4 \
test_write.m4 ref_tst_diskless2.cdl tst_diskless5.cdl \
ref_tst_diskless3_create.cdl ref_tst_diskless3_open.cdl \
run_inmemory.sh run_mmap.sh f03tst_open_mem.nc test_byterange.sh \
ref_tst_http_nc3.cdl ref_tst_http_nc4.cdl CMakeLists.txt
# These files are created by the tests.
CLEANFILES = nc_test_*.nc tst_*.nc t_nc.nc large_files.nc \
quick_large_files.nc tst_diskless3_file.cdl \
tst_diskless4.cdl ref_tst_diskless4.cdl benchmark.nc \
tst_http_nc3.cdl tst_http_nc4.cdl tmp*.cdl tmp*.nc
quick_large_files.nc tst_diskless3_file.cdl tst_diskless4.cdl \
ref_tst_diskless4.cdl benchmark.nc tst_http_nc3.cdl tst_http_nc4.cdl \
tmp*.cdl tmp*.nc
EXTRA_DIST += bad_cdf5_begin.nc run_cdf5.sh
if ENABLE_CDF5
# bad_cdf5_begin.nc is a corrupted CDF-5 file with bad variable starting
# file offsets. It is to be used by tst_open_cdf5.c to check if it can
# detect and report error code NC_ENOTNC.
TESTS += run_cdf5.sh
check_PROGRAMS += tst_open_cdf5
# bad_cdf5_begin.nc is a corrupted CDF-5 file with bad variable starting
# file offsets. It is to be used by tst_open_cdf5.c to check if it can
# detect and report error code NC_ENOTNC.
TESTS += run_cdf5.sh
check_PROGRAMS += tst_open_cdf5
if LARGE_FILE_TESTS
TESTPROGRAMS += tst_large_cdf5 tst_cdf5_begin
endif
endif
TESTPROGRAMS += tst_large_cdf5 tst_cdf5_begin
endif # LARGE_FILE_TESTS
endif # ENABLE_CDF5
# Only clean these on maintainer-clean, because they require m4 to
# regenerate.

View File

@ -299,6 +299,14 @@ main(int argc, char **argv)
}
SUMMARIZE_ERR;
printf("*** testing bad name for nc_open/nc_create with format %d... ", format[f]);
{
int ncid;
if (nc_set_default_format(format[f], NULL)) ERR;
if (nc_create(NULL, 0, &ncid) != NC_EINVAL) ERR;
if (nc_open(NULL, NC_NOWRITE, &ncid) != NC_EINVAL) ERR;
}
SUMMARIZE_ERR;
} /* next format */
}
FINAL_RESULTS;