mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +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.
55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
/*********************************************************************
|
|
* Copyright 2016, UCAR/Unidata
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
*********************************************************************/
|
|
|
|
/**
|
|
Test the netcdf-4 data building process.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "netcdf.h"
|
|
|
|
static void
|
|
fail(int code)
|
|
{
|
|
if(code != NC_NOERR)
|
|
fprintf(stderr,"***Fail: %s\n",nc_strerror(code));
|
|
exit((code==NC_NOERR?EXIT_SUCCESS:EXIT_FAILURE));
|
|
}
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
int ret = NC_NOERR;
|
|
char url[4096];
|
|
int ncid;
|
|
|
|
/* Skip cmd name */
|
|
argc++;
|
|
argv++;
|
|
|
|
if(argc < 2) {
|
|
fprintf(stderr, "too few arguments: t_dmrdata.c <infile> <outfile>\n");
|
|
fail(NC_NOERR);
|
|
}
|
|
|
|
/* build the url */
|
|
snprintf(url,sizeof(url),"file://%s#dap4&debug=copy&substratename=%s",argv[0],argv[1]);
|
|
|
|
#ifdef DEBUG
|
|
fprintf(stderr,"t_dmrbuild %s -> %s\n",url,outfile);
|
|
#endif
|
|
|
|
/* Use the open/close mechanism */
|
|
if((ret=nc_open(url,NC_NETCDF4,&ncid))) goto done;
|
|
if((ret=nc_close(ncid))) goto done;
|
|
|
|
done:
|
|
#ifdef DEBUG
|
|
fprintf(stderr,"code=%d %s\n",ret,nc_strerror(ret));
|
|
#endif
|
|
return (ret ? 1 : 0);
|
|
}
|