Переглянути джерело

Qdevice: Fix errors found by coverity

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse 9 роки тому
батько
коміт
792b4ed061

+ 3 - 3
qdevices/pr-poll-array.c

@@ -79,6 +79,9 @@ pr_poll_array_realloc(struct pr_poll_array *poll_array,
 		return (-1);
 		return (-1);
 	}
 	}
 
 
+	poll_array->allocated = new_array_size;
+	poll_array->array = new_array;
+
 	if (poll_array->user_data_size > 0) {
 	if (poll_array->user_data_size > 0) {
 		new_user_data_array = realloc(poll_array->user_data_array,
 		new_user_data_array = realloc(poll_array->user_data_array,
 		    poll_array->user_data_size * new_array_size);
 		    poll_array->user_data_size * new_array_size);
@@ -90,9 +93,6 @@ pr_poll_array_realloc(struct pr_poll_array *poll_array,
 		poll_array->user_data_array = new_user_data_array;
 		poll_array->user_data_array = new_user_data_array;
 	}
 	}
 
 
-	poll_array->allocated = new_array_size;
-	poll_array->array = new_array;
-
 	return (0);
 	return (0);
 }
 }
 
 

+ 3 - 3
qdevices/qdevice-ipc.c

@@ -133,8 +133,9 @@ qdevice_ipc_accept(struct qdevice_instance *instance, struct unix_socket_client
 		qdevice_log(LOG_ERR, "Can't alloc IPC client user data");
 		qdevice_log(LOG_ERR, "Can't alloc IPC client user data");
 		res = -1;
 		res = -1;
 		qdevice_ipc_client_disconnect(instance, *res_client);
 		qdevice_ipc_client_disconnect(instance, *res_client);
+	} else {
+		memset((*res_client)->user_data, 0, sizeof(struct qdevice_ipc_user_data));
 	}
 	}
-	memset((*res_client)->user_data, 0, sizeof(struct qdevice_ipc_user_data));
 
 
 return_res:
 return_res:
 	return (res);
 	return (res);
@@ -232,9 +233,8 @@ qdevice_ipc_parse_line(struct qdevice_instance *instance, struct unix_socket_cli
 		}
 		}
 	} else if (strcasecmp(str, "status") == 0) {
 	} else if (strcasecmp(str, "status") == 0) {
 		token = dynar_simple_lex_token_next(&lex);
 		token = dynar_simple_lex_token_next(&lex);
-		str = dynar_data(token);
 
 
-		if (token != NULL && strcmp(str, "") != 0) {
+		if (token != NULL && (str = dynar_data(token), strcmp(str, "")) != 0) {
 			if (strcasecmp(str, "verbose") == 0) {
 			if (strcasecmp(str, "verbose") == 0) {
 				verbose = 1;
 				verbose = 1;
 			}
 			}

+ 19 - 11
qdevices/qnetd-algo-ffsplit.c

@@ -324,21 +324,24 @@ qnetd_algo_ffsplit_partition_cmp(const struct qnetd_client *client1,
     const struct node_list *config_node_list2, const struct node_list *membership_node_list2)
     const struct node_list *config_node_list2, const struct node_list *membership_node_list2)
 {
 {
 	size_t part1_active_clients, part2_active_clients;
 	size_t part1_active_clients, part2_active_clients;
+	int res;
+
+	res = -1;
 
 
 	if (node_list_size(config_node_list1) % 2 != 0) {
 	if (node_list_size(config_node_list1) % 2 != 0) {
 		/*
 		/*
 		 * Odd clusters never split into 50:50.
 		 * Odd clusters never split into 50:50.
 		 */
 		 */
 		if (node_list_size(membership_node_list1) > node_list_size(config_node_list1) / 2) {
 		if (node_list_size(membership_node_list1) > node_list_size(config_node_list1) / 2) {
-			return (1);
+			res = 1; goto exit_res;
 		} else {
 		} else {
-			return (0);
+			res = 0; goto exit_res;
 		}
 		}
 	} else {
 	} else {
 		if (node_list_size(membership_node_list1) > node_list_size(config_node_list1) / 2) {
 		if (node_list_size(membership_node_list1) > node_list_size(config_node_list1) / 2) {
-			return (1);
+			res = 1; goto exit_res;
 		} else if (node_list_size(membership_node_list1) < node_list_size(config_node_list1) / 2) {
 		} else if (node_list_size(membership_node_list1) < node_list_size(config_node_list1) / 2) {
-			return (0);
+			res = 0; goto exit_res;
 		}
 		}
 
 
 		/*
 		/*
@@ -354,9 +357,9 @@ qnetd_algo_ffsplit_partition_cmp(const struct qnetd_client *client1,
 		    client2, membership_node_list2);
 		    client2, membership_node_list2);
 
 
 		if (part1_active_clients > part2_active_clients) {
 		if (part1_active_clients > part2_active_clients) {
-			return (1);
+			res = 1; goto exit_res;
 		} else if (part1_active_clients < part2_active_clients) {
 		} else if (part1_active_clients < part2_active_clients) {
-			return (0);
+			res = 0; goto exit_res;
 		}
 		}
 
 
 		/*
 		/*
@@ -365,15 +368,20 @@ qnetd_algo_ffsplit_partition_cmp(const struct qnetd_client *client1,
 
 
 		if (qnetd_algo_ffsplit_is_prefered_partition(client1, config_node_list1,
 		if (qnetd_algo_ffsplit_is_prefered_partition(client1, config_node_list1,
 		    membership_node_list1)) {
 		    membership_node_list1)) {
-			return (1);
+			res = 1; goto exit_res;
 		} else {
 		} else {
-			return (0);
+			res = 0; goto exit_res;
 		}
 		}
 	}
 	}
 
 
-	qnetd_log(LOG_CRIT, "qnetd_algo_ffsplit_partition_cmp unhandled case");
-	exit(1);
-	/* NOTREACHED */
+exit_res:
+	if (res == -1) {
+		qnetd_log(LOG_CRIT, "qnetd_algo_ffsplit_partition_cmp unhandled case");
+		exit(1);
+		/* NOTREACHED */
+	}
+
+	return (res);
 }
 }
 
 
 /*
 /*

+ 4 - 0
qdevices/qnetd-ipc.c

@@ -295,6 +295,7 @@ qnetd_ipc_parse_line(struct qnetd_instance *instance, struct unix_socket_client
 					goto exit_err_low_mem;
 					goto exit_err_low_mem;
 				}
 				}
 
 
+				free(cluster_name); cluster_name = NULL;
 				if ((cluster_name = strdup(dynar_data(token))) == NULL) {
 				if ((cluster_name = strdup(dynar_data(token))) == NULL) {
 					goto exit_err_low_mem;
 					goto exit_err_low_mem;
 				}
 				}
@@ -312,6 +313,7 @@ qnetd_ipc_parse_line(struct qnetd_instance *instance, struct unix_socket_client
 				client->schedule_disconnect = 1;
 				client->schedule_disconnect = 1;
 			}
 			}
 		}
 		}
+
 		free(cluster_name); cluster_name = NULL;
 		free(cluster_name); cluster_name = NULL;
 	} else {
 	} else {
 		qnetd_log(LOG_DEBUG, "IPC client sent unknown command");
 		qnetd_log(LOG_DEBUG, "IPC client sent unknown command");
@@ -325,6 +327,8 @@ qnetd_ipc_parse_line(struct qnetd_instance *instance, struct unix_socket_client
 	return ;
 	return ;
 
 
 exit_err_low_mem:
 exit_err_low_mem:
+	free(cluster_name); cluster_name = NULL;
+
 	qnetd_log(LOG_ERR, "Can't alloc memory for simple lex");
 	qnetd_log(LOG_ERR, "Can't alloc memory for simple lex");
 
 
 	if (qnetd_ipc_send_error(instance, client, "Command too long") != 0) {
 	if (qnetd_ipc_send_error(instance, client, "Command too long") != 0) {

+ 1 - 1
qdevices/timer-list.c

@@ -115,7 +115,7 @@ timer_list_add(struct timer_list *tlist, PRUint32 interval, timer_list_cb_fn fun
 {
 {
 	struct timer_list_entry *new_entry;
 	struct timer_list_entry *new_entry;
 
 
-	if (interval < 1 && interval > TIMER_LIST_MAX_INTERVAL) {
+	if (interval < 1 || interval > TIMER_LIST_MAX_INTERVAL) {
 		return (NULL);
 		return (NULL);
 	}
 	}
 
 

+ 2 - 2
qdevices/unix-socket.c

@@ -78,7 +78,7 @@ unix_socket_server_create(const char *path, int non_blocking, int backlog)
 	memset(&sun, 0, sizeof(sun));
 	memset(&sun, 0, sizeof(sun));
 	sun.sun_family = AF_UNIX;
 	sun.sun_family = AF_UNIX;
 
 
-	strncpy(sun.sun_path, path, sizeof(sun.sun_path));
+	strncpy(sun.sun_path, path, strlen(path));
 	unlink(path);
 	unlink(path);
 	if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) != 0) {
 	if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) != 0) {
 		close(s);
 		close(s);
@@ -121,7 +121,7 @@ unix_socket_client_create(const char *path, int non_blocking)
 	memset(&sun, 0, sizeof(sun));
 	memset(&sun, 0, sizeof(sun));
 	sun.sun_family = AF_UNIX;
 	sun.sun_family = AF_UNIX;
 
 
-	strncpy(sun.sun_path, path, sizeof(sun.sun_path));
+	strncpy(sun.sun_path, path, strlen(path));
 
 
 	if (non_blocking) {
 	if (non_blocking) {
 		if (unix_socket_set_non_blocking(s) != 0) {
 		if (unix_socket_set_non_blocking(s) != 0) {