ソースを参照

Patch to add amf_strdup instead of malloc and then copy for amf service.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1417 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 18 年 前
コミット
9d5eefa46c
2 ファイル変更35 行追加34 行削除
  1. 7 4
      exec/amf.h
  2. 28 30
      exec/amfutil.c

+ 7 - 4
exec/amf.h

@@ -664,13 +664,16 @@ struct req_exec_amf_cluster_start_tmo {
 extern struct amf_cluster *amf_config_read (char **error_string);
 extern struct amf_cluster *amf_config_read (char **error_string);
 extern void amf_runtime_attributes_print (struct amf_cluster *cluster);
 extern void amf_runtime_attributes_print (struct amf_cluster *cluster);
 extern int amf_enabled (struct objdb_iface_ver0 *objdb);
 extern int amf_enabled (struct objdb_iface_ver0 *objdb);
-extern void *_amf_malloc (size_t size, char *file, unsigned int line);
-extern void *_amf_realloc (void* ptr, size_t size, char *file, unsigned int line);
+extern void *_amf_malloc (size_t size, const char *file, unsigned int line);
 #define amf_malloc(size) _amf_malloc ((size), __FILE__, __LINE__)
 #define amf_malloc(size) _amf_malloc ((size), __FILE__, __LINE__)
-extern void *_amf_calloc (size_t nmemb, size_t size, char *file,
+extern void *_amf_realloc (void* ptr, size_t size, const char *file, 
 	unsigned int line);
 	unsigned int line);
-#define amf_calloc(nmemb,size) _amf_calloc ((nmemb), (size), __FILE__, __LINE__)
 #define amf_realloc(ptr,size) _amf_realloc ((ptr), (size), __FILE__, __LINE__)
 #define amf_realloc(ptr,size) _amf_realloc ((ptr), (size), __FILE__, __LINE__)
+extern void *_amf_calloc (size_t nmemb, size_t size, const char *file,
+	unsigned int line);
+#define amf_calloc(nmemb,size) _amf_calloc ((nmemb), (size), __FILE__, __LINE__)
+extern char *_amf_strdup (const char *str, const char *file, unsigned int line);
+#define amf_strdup(str) _amf_strdup(str, __FILE__, __LINE__)
 
 
 extern const char *amf_admin_state (int state);
 extern const char *amf_admin_state (int state);
 extern const char *amf_op_state (int state);
 extern const char *amf_op_state (int state);

+ 28 - 30
exec/amfutil.c

@@ -400,8 +400,7 @@ struct amf_cluster *amf_config_read (char **error_string)
 
 
 		case AMF_APPLICATION:
 		case AMF_APPLICATION:
 			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
 			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
-				app->clccli_path = amf_malloc (strlen (loc) + 1);
-				strcpy (app->clccli_path, loc);
+				app->clccli_path = amf_strdup(loc);
 			} else if ((loc = strstr_rs (line, "safSg=")) != 0) {
 			} else if ((loc = strstr_rs (line, "safSg=")) != 0) {
 				sg = amf_sg_new (app, trim_str (loc));
 				sg = amf_sg_new (app, trim_str (loc));
 				sg_cnt++;
 				sg_cnt++;
@@ -440,8 +439,7 @@ struct amf_cluster *amf_config_read (char **error_string)
 
 
 		case AMF_SG:
 		case AMF_SG:
 			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
 			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
-				sg->clccli_path = amf_malloc (strlen (loc) + 1);
-				strcpy (sg->clccli_path, loc);
+				sg->clccli_path = amf_strdup(loc);
 			} else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) {
 				if (strcmp (loc, "2n") == 0) {
 				if (strcmp (loc, "2n") == 0) {
 					sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL;
 					sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL;
@@ -536,8 +534,7 @@ struct amf_cluster *amf_config_read (char **error_string)
 			} else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) {
 				su->saAmfSUFailover = atoi (loc);
 				su->saAmfSUFailover = atoi (loc);
 			} else if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
 			} else if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
-				su->clccli_path = amf_malloc (strlen (loc) + 1);
-				strcpy (su->clccli_path, loc);
+				su->clccli_path = amf_strdup(loc);
 			} else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) {
 				setSaNameT (&su->saAmfSUHostedByNode, loc);
 				setSaNameT (&su->saAmfSUHostedByNode, loc);
 			} else if ((loc = strstr_rs (line, "safComp=")) != 0) {
 			} else if ((loc = strstr_rs (line, "safComp=")) != 0) {
@@ -570,8 +567,7 @@ struct amf_cluster *amf_config_read (char **error_string)
 
 
 		case AMF_COMP:
 		case AMF_COMP:
 			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
 			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
-				comp->clccli_path = amf_malloc (strlen (loc) + 1);
-				strcpy (comp->clccli_path, loc);
+				comp->clccli_path = amf_strdup(loc);
 			} else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) {
 				current_parse = AMF_COMP_CS_TYPE;
 				current_parse = AMF_COMP_CS_TYPE;
 			} else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) {
 			} else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) {
@@ -595,11 +591,9 @@ struct amf_cluster *amf_config_read (char **error_string)
 			} else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) {
 			} else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) {
 				comp->saAmfCompDefaultCallbackTimeOut = atol (loc);
 				comp->saAmfCompDefaultCallbackTimeOut = atol (loc);
 			} else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) {
-				comp->saAmfCompInstantiateCmdArgv = amf_malloc (strlen(loc) + 1);
-				strcpy (comp->saAmfCompInstantiateCmdArgv, loc);
+				comp->saAmfCompInstantiateCmdArgv = amf_strdup(loc);
 			} else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) {
 			} else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) {
-				comp->saAmfCompInstantiateCmd = amf_malloc (strlen(loc) + 1);
-				strcpy (comp->saAmfCompInstantiateCmd, loc);
+				comp->saAmfCompInstantiateCmd = amf_strdup(loc);
 			} else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) {
 			} else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) {
 				comp->saAmfCompInstantiateTimeout = atol (loc);
 				comp->saAmfCompInstantiateTimeout = atol (loc);
 			} else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) {
 			} else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) {
@@ -611,19 +605,15 @@ struct amf_cluster *amf_config_read (char **error_string)
 			} else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) {
 			} else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) {
 				comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc);
 				comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc);
 			} else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) {
-				comp->saAmfCompTerminateCmdArgv = amf_malloc (strlen(loc) + 1);
-				strcpy (comp->saAmfCompTerminateCmdArgv, loc);
+				comp->saAmfCompTerminateCmdArgv = amf_strdup(loc);
 			} else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) {
-				comp->saAmfCompTerminateCmd = amf_malloc (strlen(loc) + 1);
-				strcpy (comp->saAmfCompTerminateCmd, loc);
+				comp->saAmfCompTerminateCmd = amf_strdup(loc);
 			} else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) {
 			} else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) {
 				comp->saAmfCompTerminateTimeout = atol (loc);
 				comp->saAmfCompTerminateTimeout = atol (loc);
 			} else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) {
-				comp->saAmfCompCleanupCmdArgv = amf_malloc (strlen(loc) + 1);
-				strcpy (comp->saAmfCompCleanupCmdArgv, loc);
+				comp->saAmfCompCleanupCmdArgv = amf_strdup(loc);
 			} else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) {
-				comp->saAmfCompCleanupCmd = amf_malloc (strlen(loc) + 1);
-				strcpy (comp->saAmfCompCleanupCmd, loc);
+				comp->saAmfCompCleanupCmd = amf_strdup(loc);
 			} else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) {
 			} else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) {
 				comp->saAmfCompCleanupTimeout = atol (loc);
 				comp->saAmfCompCleanupTimeout = atol (loc);
 			} else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) {
 			} else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) {
@@ -727,8 +717,7 @@ struct amf_cluster *amf_config_read (char **error_string)
 				comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv,
 				comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv,
 					(comp_env_var_cnt + 1) * sizeof(SaStringT));
 					(comp_env_var_cnt + 1) * sizeof(SaStringT));
 				comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL;
 				comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL;
-				env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = amf_malloc (strlen (line) + 1);
-				strcpy (env_var, line);
+				env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = amf_strdup(line);
 			} else {
 			} else {
 				goto parse_error;
 				goto parse_error;
 			}
 			}
@@ -815,8 +804,7 @@ struct amf_cluster *amf_config_read (char **error_string)
 				attribute = calloc (1, sizeof(struct amf_csi_attribute));
 				attribute = calloc (1, sizeof(struct amf_csi_attribute));
 				attribute->next = csi->attributes_head;
 				attribute->next = csi->attributes_head;
 				csi->attributes_head = attribute;
 				csi->attributes_head = attribute;
-				attribute->name = amf_malloc (strlen (loc) + 1);
-				strcpy (attribute->name, trim_str (loc));
+				attribute->name = amf_strdup(loc);
 				csi_attr_cnt = 1;
 				csi_attr_cnt = 1;
 				current_parse = AMF_CSI_ATTRIBUTE;
 				current_parse = AMF_CSI_ATTRIBUTE;
 			} else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) {
 			} else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) {
@@ -857,9 +845,7 @@ struct amf_cluster *amf_config_read (char **error_string)
 				value = rm_beginning_ws (line);
 				value = rm_beginning_ws (line);
 				attribute->value = realloc (attribute->value,
 				attribute->value = realloc (attribute->value,
 					sizeof (SaStringT) * (csi_attr_cnt + 1));
 					sizeof (SaStringT) * (csi_attr_cnt + 1));
-				attribute->value[csi_attr_cnt - 1] =
-					amf_malloc (strlen (value) + 1);
-				strcpy (attribute->value[csi_attr_cnt - 1], value);
+				attribute->value[csi_attr_cnt - 1] = amf_strdup(value);
 				attribute->value[csi_attr_cnt] = NULL;
 				attribute->value[csi_attr_cnt] = NULL;
 				csi_attr_cnt++;
 				csi_attr_cnt++;
 			}
 			}
@@ -1219,7 +1205,7 @@ char *amf_deserialize_opaque (char *buf, void *dst, int *cnt)
 	return buf + *cnt + sizeof (SaUint32T);
 	return buf + *cnt + sizeof (SaUint32T);
 }
 }
 
 
-void *_amf_malloc (size_t size, char *file, unsigned int line)
+void *_amf_malloc (size_t size, const char *file, unsigned int line)
 {
 {
 	void *tmp = malloc (size);
 	void *tmp = malloc (size);
 
 
@@ -1231,7 +1217,7 @@ void *_amf_malloc (size_t size, char *file, unsigned int line)
 	return tmp;
 	return tmp;
 }
 }
 
 
-void *_amf_calloc (size_t nmemb, size_t size, char *file, unsigned int line)
+void *_amf_calloc (size_t nmemb, size_t size, const char *file, unsigned int line)
 {
 {
 	void *tmp = calloc (nmemb, size);
 	void *tmp = calloc (nmemb, size);
 
 
@@ -1243,7 +1229,7 @@ void *_amf_calloc (size_t nmemb, size_t size, char *file, unsigned int line)
 	return tmp;
 	return tmp;
 }
 }
 
 
-void *_amf_realloc (void* ptr, size_t size, char *file, unsigned int line)
+void *_amf_realloc (void* ptr, size_t size, const char *file, unsigned int line)
 {
 {
 	void *tmp = realloc (ptr, size);
 	void *tmp = realloc (ptr, size);
 
 
@@ -1255,6 +1241,18 @@ void *_amf_realloc (void* ptr, size_t size, char *file, unsigned int line)
 	return tmp;
 	return tmp;
 }
 }
 
 
+char *_amf_strdup (const char *in_str, const char *file, unsigned int line)
+{
+	char *out_str = strdup (in_str);
+
+	if (out_str == NULL) {
+		log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line);
+		openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
+	}
+
+	return out_str;
+}
+
 int sa_amf_grep_one_sub_match(const char *string, char *pattern, 
 int sa_amf_grep_one_sub_match(const char *string, char *pattern, 
 	SaNameT *matches_arr)
 	SaNameT *matches_arr)
 {
 {