netcdf-c/include/ncconfigure.h
Dennis Heimbigner 4db4393e69 Begin changing over to use strlcat instead of strncat because
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.
2017-11-23 10:55:24 -07:00

86 lines
1.6 KiB
C

/*
* Copyright 2010 University Corporation for Atmospheric
* Research/Unidata. See COPYRIGHT file for more info.
*
* This header file is for the parallel I/O functions of netCDF.
*
*/
/* "$Id: netcdf_par.h,v 1.1 2010/06/01 15:46:49 ed Exp $" */
#ifndef NCCONFIGURE_H
#define NCCONFIGURE_H 1
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
/*
This is included in bottom
of config.h. It is where,
typically, alternatives to
missing functions should be
defined.
*/
#ifndef HAVE_STRDUP
extern char* strdup(const char*);
#endif
/* #if HAVE_BASETSD_H */
/* #ifndef ssize_t */
/* #ifndef SSIZE_T */
/* #include <BaseTsd.h> */
/* #endif */
/* #define ssize_t SSIZE_T */
/* #endif */
/* #endif */
/* handle null arguments */
#ifndef nulldup
#ifdef HAVE_STRDUP
#define nulldup(s) ((s)==NULL?NULL:strdup(s))
#else
char *nulldup(const char* s);
#endif
#endif
#ifndef HAVE_STRLCAT
#ifdef _MSC_VER
/* Windows strlcat_s is equivalent to strlcat, but different arg order */
#define strlcat(d,s,n) strcat_s((d),(n),(s))
#else
extern size_t strlcat(char* dst, const char* src, size_t dsize);
#endif
#endif
#ifndef nulldup
#define nulldup(s) ((s)==NULL?NULL:strdup(s))
#endif
#ifndef nulllen
#define nulllen(s) ((s)==NULL?0:strlen(s))
#endif
#ifndef nullfree
#define nullfree(s) {if((s)!=NULL) {free(s);} else {}}
#endif
#ifndef HAVE_UCHAR
typedef unsigned char uchar;
#endif
#ifndef HAVE_LONGLONG
typedef long long longlong;
typedef unsigned long long ulonglong;
#endif
#ifndef HAVE_USHORT
typedef unsigned short ushort;
#endif
#ifndef HAVE_UINT
typedef unsigned int uint;
#endif
#endif /* NCCONFIGURE_H */