From c1101a47196053697304a455da975fa59debc853 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 12 Dec 2024 15:19:07 +0100 Subject: [PATCH] Don't include system headers in php_config.h Configuration headers (config.h, etc.), as their name implies, are supposed to contain macro definitions to avoid having them to pass on the command line[1]. It seems fine if they include other configuration headers when needed. In any way, they are supposed to be included very early in compilation units which require them. Doing more than defining simple macros, possibly guarded by defines set during compile time (such as a compiler or platform identification), can lead to subtle issues, which may go unnoticed such as the fallback definitions in the hard-coded (!) fpm_config.h, which may actually be used unconditionally, because the appropriate system headers have not already been included. [1] --- TSRM/TSRM.h | 19 +++++++++++++++++++ Zend/zend.h | 26 ++++++++++++++++++++++++++ Zend/zend_config.w32.h | 16 ---------------- configure.ac | 12 ------------ sapi/fpm/fpm/fpm.h | 1 + sapi/fpm/fpm/fpm_events.h | 2 ++ 6 files changed, 48 insertions(+), 28 deletions(-) diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h index 80d6cbad04435..e309a07f034ce 100644 --- a/TSRM/TSRM.h +++ b/TSRM/TSRM.h @@ -16,8 +16,27 @@ #if !defined(__CYGWIN__) && defined(_WIN32) # define TSRM_WIN32 # include +# define _CRTDBG_MAP_ALLOC +# include +# include +# include +# include +# ifndef ZEND_INCLUDE_FULL_WINDOWS_HEADERS +# define WIN32_LEAN_AND_MEAN +# endif +# include +# include +# include #else # include
+# include +# ifdef HAVE_SYS_TYPES_H +# include +# endif +# ifdef HAVE_SYS_SELECT_H +# include +# endif +# include #endif #include diff --git a/Zend/zend.h b/Zend/zend.h index 0cf1faeb653fe..3f88c9d50fd37 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -24,6 +24,32 @@ #define ZEND_ENGINE_3 +#if !defined(__CYGWIN__) && defined(_WIN32) +# define TSRM_WIN32 +# include +# define _CRTDBG_MAP_ALLOC +# include +# include +# include +# include +# ifndef ZEND_INCLUDE_FULL_WINDOWS_HEADERS +# define WIN32_LEAN_AND_MEAN +# endif +# include +# include +# include +#else +# include
+# include +# ifdef HAVE_SYS_TYPES_H +# include +# endif +# ifdef HAVE_SYS_SELECT_H +# include +# endif +# include +#endif + #include "zend_types.h" #include "zend_map_ptr.h" #include "zend_errors.h" diff --git a/Zend/zend_config.w32.h b/Zend/zend_config.w32.h index ffd5f1736ee4a..5b324fe2938b0 100644 --- a/Zend/zend_config.w32.h +++ b/Zend/zend_config.w32.h @@ -22,22 +22,6 @@ #include <../main/config.w32.h> -#define _CRTDBG_MAP_ALLOC - -#include -#include -#include - -#include - -#ifndef ZEND_INCLUDE_FULL_WINDOWS_HEADERS -#define WIN32_LEAN_AND_MEAN -#endif -#include -#include - -#include - #if _MSC_VER < 1900 #define snprintf _snprintf #endif diff --git a/configure.ac b/configure.ac index 01d9ded69b920..2483a3d23e53c 100644 --- a/configure.ac +++ b/configure.ac @@ -43,18 +43,6 @@ AH_TOP([ #define ZEND_DLIMPORT ]) AH_BOTTOM([ -#include - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#ifdef HAVE_SYS_SELECT_H -#include -#endif - -#include - #endif /* PHP_CONFIG_H */ ]) diff --git a/sapi/fpm/fpm/fpm.h b/sapi/fpm/fpm/fpm.h index ec036a2d68198..a82f5ab640e9c 100644 --- a/sapi/fpm/fpm/fpm.h +++ b/sapi/fpm/fpm/fpm.h @@ -3,6 +3,7 @@ #ifndef FPM_H #define FPM_H 1 +#include #include #ifdef HAVE_SYSEXITS_H diff --git a/sapi/fpm/fpm/fpm_events.h b/sapi/fpm/fpm/fpm_events.h index 8097477c827f3..2e6904abaa1c7 100644 --- a/sapi/fpm/fpm/fpm_events.h +++ b/sapi/fpm/fpm/fpm_events.h @@ -3,6 +3,8 @@ #ifndef FPM_EVENTS_H #define FPM_EVENTS_H 1 +#include + #define FPM_EV_TIMEOUT (1 << 0) #define FPM_EV_READ (1 << 1) #define FPM_EV_PERSIST (1 << 2)