mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-21 08:39:46 +08:00
4db4393e69
strlcat provides better protection against buffer overflows. Code is taken from the FreeBSD project source code. Specifically: https://github.com/freebsd/freebsd/blob/master/lib/libc/string/strlcat.c License appears to be acceptable, but needs to be checked by e.g. Debian. Step 1: 1. Add to netcdf-c/include/ncconfigure.h to use our version if not already available as determined by HAVE_STRLCAT in config.h. 2. Add the strlcat code to libdispatch/dstring.c 3. Turns out that strlcat was already defined in several places. So remove it from: ncgen3/genlib.c ncdump/dumplib.c 3. Define strlcat extern definition in ncconfigure.h. 4. Modify following directories to use strlcat: libdap2 libdap4 ncdap_test dap4_test Will do others in subsequent steps.
52 lines
1.0 KiB
C
52 lines
1.0 KiB
C
#include "config.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "netcdf.h"
|
|
#include "t_srcdir.h"
|
|
|
|
#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;
|
|
const char* topsrcdir;
|
|
char url[4096];
|
|
|
|
|
|
topsrcdir = gettopsrcdir();
|
|
|
|
strncpy(url,"file://",sizeof(url));
|
|
strlcat(url,topsrcdir,sizeof(url));
|
|
strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url));
|
|
|
|
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;
|
|
}
|