mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
added validation checks for dap when doing get_vara
This commit is contained in:
parent
27c75fd0be
commit
132359d2cb
@ -55,7 +55,7 @@ NC_testurl(const char* path)
|
||||
if(path == NULL) return 0;
|
||||
|
||||
/* find leading non-blank */
|
||||
for(p=path;*p;p++) {if(*p != ' ') break;}
|
||||
for(p=(char*)path;*p;p++) {if(*p != ' ') break;}
|
||||
|
||||
/* Do some initial checking to see if this looks like a file path */
|
||||
if(*p == '/') return 0; /* probably an absolute file path */
|
||||
|
@ -231,7 +231,6 @@ nc_urlparamdecode(char* params0)
|
||||
int nparams;
|
||||
NClist* map = nclistnew();
|
||||
char* params;
|
||||
char* tmp;
|
||||
|
||||
if(params0 == NULL) return map;
|
||||
|
||||
|
@ -261,7 +261,7 @@ vpt::
|
||||
##################################################
|
||||
#T=test_varm3
|
||||
#T=t_dap3b
|
||||
T=test_vara
|
||||
T=t_dap3c
|
||||
|
||||
v::
|
||||
cc -g -c ${T}.c ${INCL}
|
||||
|
@ -80,14 +80,15 @@ LDADD += ${top_builddir}/libncdap3/libncdap3.la \
|
||||
LDADD += @EXTERN_LDFLAGS@
|
||||
|
||||
# Add a trivial test case to check for undefined references
|
||||
check_PROGRAMS = t_dap3a
|
||||
CLEANFILES += t_dap3a
|
||||
check_PROGRAMS = t_dap3a t_dap3c
|
||||
CLEANFILES += t_dap3a t_dap3c
|
||||
TESTS_ENVIRONMENT=TOPSRCDIR=${abs_top_srcdir}
|
||||
TESTS = t_dap3a
|
||||
TESTS = t_dap3a t_dap3c
|
||||
t_dap3a_SOURCES = t_dap3a.c stubdap3.c
|
||||
t_dap3c_SOURCES = t_dap3c.c stubdap3.c
|
||||
# Set ldflags
|
||||
t_dap3a_LDFLAGS = ${top_builddir}/libsrc/libnetcdf3.la ${top_builddir}/libdispatch/libdispatch.la
|
||||
|
||||
t_dap3c_LDFLAGS = ${t_dap3a_LDFLAGS}
|
||||
EXTRA_DIST = ce.y t_dap.c
|
||||
|
||||
endif # BUILD_DAP
|
||||
|
@ -44,9 +44,11 @@ nc3d_getvarx(int ncid, int varid,
|
||||
CDFnode* target = NULL; /* target in constrained DDS */
|
||||
NCprojection* varaprojection = NULL;
|
||||
NCcachenode* cachenode = NULL;
|
||||
size_t localcount[NC_MAX_VAR_DIMS];
|
||||
NClist* vars = nclistnew();
|
||||
NCconstraint* constraint = NULL;
|
||||
size_t localcount[NC_MAX_VAR_DIMS];
|
||||
NClist* ncdims;
|
||||
size_t ncrank;
|
||||
|
||||
ncstat = NC_check_id(ncid, (NC**)&drno);
|
||||
if(ncstat != NC_NOERR) goto fail;
|
||||
@ -69,10 +71,16 @@ nc3d_getvarx(int ncid, int varid,
|
||||
ASSERT((cdfvar != NULL));
|
||||
ASSERT((strcmp(cdfvar->ncfullname,var->name->cp)==0));
|
||||
|
||||
/* Get the dimension info */
|
||||
ncdims = cdfvar->array.dimensions;
|
||||
ncrank = nclistlength(ncdims);
|
||||
|
||||
/* Fill in missing arguments */
|
||||
if(startp == NULL)
|
||||
startp = dapzerostart3;
|
||||
|
||||
if(countp == NULL) {
|
||||
/* Accumulate the dimension sizes */
|
||||
NClist* ncdims = cdfvar->array.dimensions;
|
||||
size_t ncrank = nclistlength(ncdims);
|
||||
for(i=0;i<ncrank;i++) {
|
||||
CDFnode* dim = (CDFnode*)nclistget(ncdims,i);
|
||||
localcount[i] = dim->dim.declsize;
|
||||
@ -80,6 +88,19 @@ nc3d_getvarx(int ncid, int varid,
|
||||
countp = localcount;
|
||||
}
|
||||
|
||||
if(stridep == NULL)
|
||||
stridep = dapsinglestride3;
|
||||
|
||||
/* Validate the dimension sizes */
|
||||
for(i=0;i<ncrank;i++) {
|
||||
CDFnode* dim = (CDFnode*)nclistget(ncdims,i);
|
||||
if(startp[i] > dim->dim.declsize
|
||||
|| startp[i]+countp[i] > dim->dim.declsize) {
|
||||
ncstat = NC_EINVALCOORDS;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{ NClist* dims = cdfvar->array.dimensions;
|
||||
fprintf(stderr,"getvarx: %s",cdfvar->ncfullname);
|
||||
@ -708,7 +729,7 @@ nc3d_getvarmx(int ncid, int varid,
|
||||
called?) */
|
||||
/* recurse with additional parameters */
|
||||
return THROW(nc3d_getvarx(ncid,varid,
|
||||
dapzerostart3,NULL,dapsinglestride3,
|
||||
NULL,NULL,NULL,
|
||||
data,dsttype0));
|
||||
}
|
||||
|
||||
|
@ -46,20 +46,6 @@ extern "C" {
|
||||
* The Interface
|
||||
*/
|
||||
|
||||
/* Declaration modifiers for DLL support (MSC et al) */
|
||||
|
||||
#if defined(DLL_NETCDF) /* define when library is a DLL */
|
||||
# if defined(DLL_EXPORT) /* define when building the library */
|
||||
# define MSC_EXTRA __declspec(dllexport)
|
||||
# else
|
||||
# define MSC_EXTRA __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
#define MSC_EXTRA
|
||||
#endif /* defined(DLL_NETCDF) */
|
||||
|
||||
# define EXTERNL extern MSC_EXTRA
|
||||
|
||||
EXTERNL int
|
||||
NCD3_new_nc(struct NC**);
|
||||
|
||||
|
@ -130,7 +130,7 @@ extern NCerror buildvaraprojection3(struct Getvara*,
|
||||
extern NCerror nc3d_getvarx(int ncid, int varid,
|
||||
const size_t *startp,
|
||||
const size_t *countp,
|
||||
const ptrdiff_t* stridep,
|
||||
const ptrdiff_t *stridep,
|
||||
void *data,
|
||||
nc_type dsttype0);
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#define NETCDF3ONLY
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
|
42
libncdap3/t_dap3c.c
Normal file
42
libncdap3/t_dap3c.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netcdf.h>
|
||||
|
||||
#define URL "http://test.opendap.org:8080/dods/dts/test.02"
|
||||
#define VAR "i32"
|
||||
|
||||
#define ERRCODE 2
|
||||
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int ncid, varid;
|
||||
int retval;
|
||||
int i32[100];
|
||||
size_t start[1];
|
||||
size_t count[1];
|
||||
int ok = 1;
|
||||
|
||||
if ((retval = nc_open(URL, 0, &ncid)))
|
||||
ERR(retval);
|
||||
if ((retval = nc_inq_varid(ncid, VAR, &varid)))
|
||||
ERR(retval);
|
||||
|
||||
start[0] = 0;
|
||||
count[0] = 26;
|
||||
if ((retval = nc_get_vara_int(ncid, varid, start, count, i32)))
|
||||
if(retval != NC_EINVALCOORDS) {
|
||||
printf("nc_get_vara_int did not return NC_EINVALCOORDS");
|
||||
ok = 0;
|
||||
}
|
||||
|
||||
nc_close(ncid);
|
||||
|
||||
printf(ok?"*** PASS\n":"*** FAIL\n");
|
||||
return 0;
|
||||
}
|
@ -56,16 +56,19 @@ LDADD += ${top_builddir}/oc/liboc.la
|
||||
LDADD += @EXTERN_LDFLAGS@
|
||||
|
||||
# Add a trivial test case to check for undefined references
|
||||
check_PROGRAMS = t_dap4
|
||||
check_PROGRAMS = t_dap4 t_dap4c
|
||||
TESTS_ENVIRONMENT=TOPSRCDIR=${abs_top_srcdir}
|
||||
TESTS = t_dap4
|
||||
TESTS = t_dap4 t_dap4c
|
||||
t_dap4_SOURCES = t_dap4.c stubdap4.c
|
||||
CLEANFILES += t_dap4
|
||||
t_dap4c_SOURCES = t_dap4c.c stubdap4.c
|
||||
CLEANFILES += t_dap4 t_dap4c
|
||||
|
||||
# This rule are used if someone wants to rebuild t_dap4.c
|
||||
# Otherwise never invoked, but records how to do it.
|
||||
t_dap4.c: ../libncdap3/t_dap.c
|
||||
cat ../libncdap3/t_dap.c >> ./t_dap4.c
|
||||
t_dap4c.c: ../libncdap3/t_dap3c.c
|
||||
cat ../libncdap3/t_dap3c.c >> ./t_dap4c.c
|
||||
|
||||
endif # USE_NETCDF4
|
||||
|
||||
|
@ -38,6 +38,9 @@ NCD4_get_vara(int ncid, int varid,
|
||||
NCprojection* varaprojection = NULL;
|
||||
NCcachenode* cachenode = NULL;
|
||||
nc_type externaltype = externaltype0;
|
||||
size_t localcount[NC_MAX_VAR_DIMS];
|
||||
NClist* ncdims;
|
||||
size_t ncrank;
|
||||
|
||||
LOG((2, "nc_get_vara: ncid 0x%x varid %d", ncid, varid));
|
||||
|
||||
@ -64,6 +67,33 @@ NCD4_get_vara(int ncid, int varid,
|
||||
ASSERT((cdfvar != NULL));
|
||||
ASSERT((strcmp(cdfvar->ncfullname,var->name)==0));
|
||||
|
||||
/* Get the dimension info */
|
||||
ncdims = cdfvar->array.dimensions;
|
||||
ncrank = nclistlength(ncdims);
|
||||
|
||||
/* Fill in missing arguments */
|
||||
if(startp == NULL)
|
||||
startp = dapzerostart3;
|
||||
|
||||
if(countp == NULL) {
|
||||
/* Accumulate the dimension sizes */
|
||||
for(i=0;i<ncrank;i++) {
|
||||
CDFnode* dim = (CDFnode*)nclistget(ncdims,i);
|
||||
localcount[i] = dim->dim.declsize;
|
||||
}
|
||||
countp = localcount;
|
||||
}
|
||||
|
||||
/* Validate the dimension sizes */
|
||||
for(i=0;i<ncrank;i++) {
|
||||
CDFnode* dim = (CDFnode*)nclistget(ncdims,i);
|
||||
if(startp[i] > dim->dim.declsize
|
||||
|| startp[i]+countp[i] > dim->dim.declsize) {
|
||||
ncstat = NC_EINVALCOORDS;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{ NClist* dims = cdfvar->array.dimensions;
|
||||
fprintf(stderr,"getvarx: %s/%d",cdfvar->ncfullname,(int)nclistlength(dims));
|
||||
|
@ -46,21 +46,6 @@ extern "C" {
|
||||
* The Interface
|
||||
*/
|
||||
|
||||
/* Declaration modifiers for DLL support (MSC et al) */
|
||||
|
||||
#if defined(DLL_NETCDF) /* define when library is a DLL */
|
||||
# if defined(DLL_EXPORT) /* define when building the library */
|
||||
# define MSC_EXTRA __declspec(dllexport)
|
||||
# else
|
||||
# define MSC_EXTRA __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
#define MSC_EXTRA
|
||||
#endif /* defined(DLL_NETCDF) */
|
||||
|
||||
# define EXTERNL extern MSC_EXTRA
|
||||
|
||||
/**/
|
||||
|
||||
EXTERNL int
|
||||
NCD4_new_nc(NC**);
|
||||
|
@ -229,7 +229,6 @@ dumpmem2(char* s, char* accum, int align)
|
||||
static void
|
||||
dumpmem1(int index, unsigned int n, unsigned int n1)
|
||||
{
|
||||
int i;
|
||||
char s[1024];
|
||||
char tmp[32];
|
||||
union {
|
||||
@ -238,10 +237,13 @@ dumpmem1(int index, unsigned int n, unsigned int n1)
|
||||
unsigned char cv[4];
|
||||
float fv;
|
||||
} form;
|
||||
#ifndef CRUDE
|
||||
int i;
|
||||
union {
|
||||
unsigned int uv[2];
|
||||
double dv;
|
||||
} dform;
|
||||
#endif
|
||||
form.uv = n;
|
||||
s[0] = '\0';
|
||||
#ifndef CRUDE
|
||||
@ -283,8 +285,9 @@ dumpmemory0(char* memory, int len, int fromxdr, int bod)
|
||||
{
|
||||
unsigned int i,count,rem;
|
||||
int* imemory;
|
||||
#ifndef CRUDE
|
||||
char hdr[1024];
|
||||
|
||||
#endif
|
||||
assert(memory[len] == 0);
|
||||
|
||||
#ifndef CRUDE
|
||||
|
Loading…
Reference in New Issue
Block a user