소스 검색

core: cfg struct - pack structures that use a dynamic array at the end

- compiler padding to alling fields results in wrong offset for last
field which is computed as `sizeof(struct) - 1
- GH #1583
Daniel-Constantin Mierla 7 년 전
부모
커밋
7bc82ef842
1개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 1
      src/core/cfg/cfg_struct.h

+ 9 - 1
src/core/cfg/cfg_struct.h

@@ -40,22 +40,24 @@
  * When the config is shmzied, these variables are combined in
  * When the config is shmzied, these variables are combined in
  * an array.
  * an array.
  */
  */
+#pragma pack(push, 1)
 typedef struct _cfg_add_var {
 typedef struct _cfg_add_var {
 	struct _cfg_add_var	*next;
 	struct _cfg_add_var	*next;
 	unsigned int	type;	/*!< type == 0 is also valid, it indicates that the group
 	unsigned int	type;	/*!< type == 0 is also valid, it indicates that the group
 				must be created with the default values */
 				must be created with the default values */
+	unsigned int	group_id; /*!< Id of the group instance */
 	union {
 	union {
 		char	*ch;
 		char	*ch;
 		str	s;
 		str	s;
 		int	i;
 		int	i;
 	} val;
 	} val;
-	unsigned int	group_id; /*!< Id of the group instance */
 	int		name_len;	/*!< Name of the variable. The variable may not be known,
 	int		name_len;	/*!< Name of the variable. The variable may not be known,
 					for example the additional group value is set in the script
 					for example the additional group value is set in the script
 					before the cfg group is declared. Hence, the pointer cannot
 					before the cfg group is declared. Hence, the pointer cannot
 					be stored here. */
 					be stored here. */
 	char		name[1];
 	char		name[1];
 } cfg_add_var_t;
 } cfg_add_var_t;
+#pragma pack(pop)
 
 
 /*! \brief structure used for variable - pointer mapping */
 /*! \brief structure used for variable - pointer mapping */
 typedef struct _cfg_mapping {
 typedef struct _cfg_mapping {
@@ -72,6 +74,7 @@ typedef struct _cfg_mapping {
 enum { CFG_GROUP_UNKNOWN = 0, CFG_GROUP_DYNAMIC, CFG_GROUP_STATIC };
 enum { CFG_GROUP_UNKNOWN = 0, CFG_GROUP_DYNAMIC, CFG_GROUP_STATIC };
 
 
 /*! \brief linked list of registered groups */
 /*! \brief linked list of registered groups */
+#pragma pack(push, 1)
 typedef struct _cfg_group {
 typedef struct _cfg_group {
 	int		num;		/*!< number of variables within the group */
 	int		num;		/*!< number of variables within the group */
 	cfg_mapping_t	*mapping;	/*!< describes the mapping betweeen
 	cfg_mapping_t	*mapping;	/*!< describes the mapping betweeen
@@ -103,9 +106,11 @@ typedef struct _cfg_group {
 	int		name_len;
 	int		name_len;
 	char		name[1];
 	char		name[1];
 } cfg_group_t;
 } cfg_group_t;
+#pragma pack(pop)
 
 
 /*! \brief One instance of the cfg group variables which stores
 /*! \brief One instance of the cfg group variables which stores
  * the additional values. These values can overwrite the default values. */
  * the additional values. These values can overwrite the default values. */
+#pragma pack(push, 1)
 typedef struct _cfg_group_inst {
 typedef struct _cfg_group_inst {
 	unsigned int	id;		/*!< identifier of the group instance */
 	unsigned int	id;		/*!< identifier of the group instance */
 	unsigned int	set[CFG_MAX_VAR_NUM/(sizeof(int)*8)];
 	unsigned int	set[CFG_MAX_VAR_NUM/(sizeof(int)*8)];
@@ -114,6 +119,7 @@ typedef struct _cfg_group_inst {
 					then the default value is used, and copied into this instance. */
 					then the default value is used, and copied into this instance. */
 	unsigned char	vars[1];	/*!< block for the values */
 	unsigned char	vars[1];	/*!< block for the values */
 } cfg_group_inst_t;
 } cfg_group_inst_t;
+#pragma pack(pop)
 
 
 /*! \brief Meta-data which is stored before each variable group
 /*! \brief Meta-data which is stored before each variable group
  * within the blob. This structure is used to handle the multivalue
  * within the blob. This structure is used to handle the multivalue
@@ -125,6 +131,7 @@ typedef struct _cfg_group_meta {
 } cfg_group_meta_t;
 } cfg_group_meta_t;
 
 
 /*! \brief single memoy block that contains all the cfg values */
 /*! \brief single memoy block that contains all the cfg values */
+#pragma pack(push, 1)
 typedef struct _cfg_block {
 typedef struct _cfg_block {
 	atomic_t	refcnt;		/*!< reference counter,
 	atomic_t	refcnt;		/*!< reference counter,
 					the block is automatically deleted
 					the block is automatically deleted
@@ -132,6 +139,7 @@ typedef struct _cfg_block {
 	int		_pad;		/*!< force 8 byte alignment */
 	int		_pad;		/*!< force 8 byte alignment */
 	unsigned char	vars[1];	/*!< blob that contains the values */
 	unsigned char	vars[1];	/*!< blob that contains the values */
 } cfg_block_t;
 } cfg_block_t;
+#pragma pack(pop)
 
 
 /*! \brief Linked list of per-child process callbacks.
 /*! \brief Linked list of per-child process callbacks.
  * Each child process has a local pointer, and executes the callbacks
  * Each child process has a local pointer, and executes the callbacks