X-Git-Url: https://vcs.fsf.org/?p=exim.git;a=blobdiff_plain;f=src%2Fsrc%2Fmytypes.h;h=fd33168f717dc692c49b8c0c12135c15c3dba5d0;hp=51a4ad49448aac8d938609937beae9df8f796087;hb=4ec0fcb6737da9bc2603056d56fbf6e41e061967;hpb=184e88237dea64ce48076cdd0184612d057cbafd diff --git a/src/src/mytypes.h b/src/src/mytypes.h index 51a4ad494..fd33168f7 100644 --- a/src/src/mytypes.h +++ b/src/src/mytypes.h @@ -1,10 +1,8 @@ -/* $Cambridge: exim/src/src/mytypes.h,v 1.4 2007/01/08 10:50:18 ph10 Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2007 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ @@ -15,19 +13,44 @@ local_scan.h includes it and exim.h includes them both (to get this earlier). */ #ifndef MYTYPES_H #define MYTYPES_H +# include + +#ifndef FALSE +# define FALSE 0 +#endif + +#ifndef TRUE +# define TRUE 1 +#endif -#define FALSE 0 -#define TRUE 1 -#define TRUE_UNSET 2 +#ifndef TRUE_UNSET +# define TRUE_UNSET 2 +#endif /* If gcc is being used to compile Exim, we can use its facility for checking the arguments of printf-like functions. This is done by a macro. */ -#ifdef __GNUC__ -#define PRINTF_FUNCTION __attribute__((format(printf,1,2))) +#if defined(__GNUC__) || defined(__clang__) +# define PRINTF_FUNCTION(A,B) __attribute__((format(printf,A,B))) +# define ARG_UNUSED __attribute__((__unused__)) +# define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) +# define ALLOC __attribute__((malloc)) +# define ALLOC_SIZE(A) __attribute__((alloc_size(A))) +# define NORETURN __attribute__((noreturn)) #else -#define PRINTF_FUNCTION +# define PRINTF_FUNCTION(A,B) +# define ARG_UNUSED /**/ +# define WARN_UNUSED_RESULT /**/ +# define ALLOC /**/ +# define ALLOC_SIZE(A) /**/ +# define NORETURN /**/ +#endif + +#ifdef WANT_DEEPER_PRINTF_CHECKS +# define ALMOST_PRINTF(A, B) PRINTF_FUNCTION(A, B) +#else +# define ALMOST_PRINTF(A, B) #endif @@ -35,8 +58,10 @@ the arguments of printf-like functions. This is done by a macro. */ the standard header files, so we use "uschar". Solaris has u_char in sys/types.h. This is just a typing convenience, of course. */ -typedef int BOOL; typedef unsigned char uschar; +typedef unsigned BOOL; +/* We also have SIGNAL_BOOL, which requires signal.h be included, so is defined +elsewhere */ /* These macros save typing for the casting that is needed to cope with the @@ -51,6 +76,7 @@ almost always literal strings. */ #define US (unsigned char *) #define CUS (const unsigned char *) #define USS (unsigned char **) +#define CUSS (const unsigned char **) /* The C library string functions expect "char *" arguments. Use macros to avoid having to write a cast each time. We do this for string and file @@ -61,7 +87,6 @@ functions that are called quite often; for other calls to external libraries #define Uatol(s) atol(CCS(s)) #define Uchdir(s) chdir(CCS(s)) #define Uchmod(s,n) chmod(CCS(s),n) -#define Uchown(s,n,m) chown(CCS(s),n,m) #define Ufgets(b,n,f) fgets(CS(b),n,f) #define Ufopen(s,t) fopen(CCS(s),CCS(t)) #define Ulink(s,t) link(CCS(s),CCS(t)) @@ -75,18 +100,20 @@ functions that are called quite often; for other calls to external libraries #define Uread(f,b,l) read(f,CS(b),l) #define Urename(s,t) rename(CCS(s),CCS(t)) #define Ustat(s,t) stat(CCS(s),t) -#define Ustrcat(s,t) strcat(CS(s),CCS(t)) +#define Ustrcat(s,t) __Ustrcat(s, CUS(t), __FUNCTION__, __LINE__) #define Ustrchr(s,n) US strchr(CCS(s),n) #define CUstrchr(s,n) CUS strchr(CCS(s),n) #define CUstrerror(n) CUS strerror(n) #define Ustrcmp(s,t) strcmp(CCS(s),CCS(t)) -#define Ustrcpy(s,t) strcpy(CS(s),CCS(t)) +#define Ustrcpy(s,t) __Ustrcpy(s, CUS(t), __FUNCTION__, __LINE__) +#define Ustrcpy_nt(s,t) strcpy(CS s, CCS t) /* no taint check */ #define Ustrcspn(s,t) strcspn(CCS(s),CCS(t)) #define Ustrftime(s,m,f,t) strftime(CS(s),m,f,t) #define Ustrlen(s) (int)strlen(CCS(s)) -#define Ustrncat(s,t,n) strncat(CS(s),CCS(t),n) +#define Ustrncat(s,t,n) __Ustrncat(s, CUS(t),n, __FUNCTION__, __LINE__) #define Ustrncmp(s,t,n) strncmp(CCS(s),CCS(t),n) -#define Ustrncpy(s,t,n) strncpy(CS(s),CCS(t),n) +#define Ustrncpy(s,t,n) __Ustrncpy(s, CUS(t),n, __FUNCTION__, __LINE__) +#define Ustrncpy_nt(s,t,n) strncpy(CS s, CCS t, n) /* no taint check */ #define Ustrpbrk(s,t) strpbrk(CCS(s),CCS(t)) #define Ustrrchr(s,n) US strrchr(CCS(s),n) #define CUstrrchr(s,n) CUS strrchr(CCS(s),n) @@ -97,6 +124,58 @@ functions that are called quite often; for other calls to external libraries #define Ustrtol(s,t,b) strtol(CCS(s),CSS(t),b) #define Ustrtoul(s,t,b) strtoul(CCS(s),CSS(t),b) #define Uunlink(s) unlink(CCS(s)) + +extern void die_tainted(const uschar *, const uschar *, int); + +/* Predicate: if an address is in a tainted pool. +By extension, a variable pointing to this address is tainted. +*/ + +static inline BOOL +is_tainted(const void * p) +{ +#if defined(COMPILE_UTILITY) || defined(MACRO_PREDEF) +return FALSE; + +#elif !defined(TAINT_CHECK_FAST) +extern BOOL is_tainted_fn(const void *); +return is_tainted_fn(p); + +#else +extern void * tainted_base, * tainted_top; +return p >= tainted_base && p < tainted_top; +#endif +} + +static inline uschar * __Ustrcat(uschar * dst, const uschar * src, const char * func, int line) +{ +#if !defined(COMPILE_UTILITY) && !defined(MACRO_PREDEF) +if (!is_tainted(dst) && is_tainted(src)) die_tainted(US"Ustrcat", CUS func, line); +#endif +return US strcat(CS dst, CCS src); +} +static inline uschar * __Ustrcpy(uschar * dst, const uschar * src, const char * func, int line) +{ +#if !defined(COMPILE_UTILITY) && !defined(MACRO_PREDEF) +if (!is_tainted(dst) && is_tainted(src)) die_tainted(US"Ustrcpy", CUS func, line); +#endif +return US strcpy(CS dst, CCS src); +} +static inline uschar * __Ustrncat(uschar * dst, const uschar * src, size_t n, const char * func, int line) +{ +#if !defined(COMPILE_UTILITY) && !defined(MACRO_PREDEF) +if (!is_tainted(dst) && is_tainted(src)) die_tainted(US"Ustrncat", CUS func, line); #endif +return US strncat(CS dst, CCS src, n); +} +static inline uschar * __Ustrncpy(uschar * dst, const uschar * src, size_t n, const char * func, int line) +{ +#if !defined(COMPILE_UTILITY) && !defined(MACRO_PREDEF) +if (!is_tainted(dst) && is_tainted(src)) die_tainted(US"Ustrncpy", CUS func, line); +#endif +return US strncpy(CS dst, CCS src, n); +} +/*XXX will likely need unchecked copy also */ +#endif /* End of mytypes.h */