Преглед на файлове

Fix few bugs found by coverity

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse преди 9 години
родител
ревизия
1925074909
променени са 11 файла, в които са добавени 44 реда и са изтрити 9 реда
  1. 1 1
      exec/cmap.c
  2. 1 0
      exec/cpg.c
  3. 7 0
      exec/totemconfig.c
  4. 2 0
      exec/votequorum.c
  5. 7 3
      lib/cfg.c
  6. 2 0
      lib/cpg.c
  7. 4 0
      test/cpgbound.c
  8. 6 1
      test/cpghum.c
  9. 4 0
      test/cpgverify.c
  10. 1 4
      test/testsam.c
  11. 9 0
      tools/corosync-cfgtool.c

+ 1 - 1
exec/cmap.c

@@ -836,7 +836,7 @@ static cs_error_t cmap_mcast_send(enum cmap_mcast_reason reason, int argc, char
 		if (item == NULL) {
 			goto free_mem;
 		}
-		memset(item, 0, sizeof(item_len));
+		memset(item, 0, item_len);
 
 		item->value_type = value_type;
 		item->value_len = value_len;

+ 1 - 0
exec/cpg.c

@@ -1809,6 +1809,7 @@ memory_map (
 
 	res = close (fd);
 	if (res) {
+		munmap (addr, bytes);
 		return (-1);
 	}
 	*buf = addr;

+ 7 - 0
exec/totemconfig.c

@@ -153,6 +153,13 @@ static void totem_volatile_config_set_value (struct totem_config *totem_config,
 	/*
 	 * Store totem_config value to cmap runtime section
 	 */
+	if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
+		/*
+		 * This shouldn't happen
+		 */
+		return ;
+	}
+
 	strcpy(runtime_key_name, "runtime.config.");
 	strcat(runtime_key_name, key_name);
 

+ 2 - 0
exec/votequorum.c

@@ -792,6 +792,7 @@ static int load_ev_tracking_barrier(void)
 	ev_tracking_fd = open(filename, O_RDWR, 0700);
 	if (ev_tracking_fd != -1) {
 		res = read (ev_tracking_fd, &ev_tracking_barrier, sizeof(uint32_t));
+		close(ev_tracking_fd);
 		if (res == sizeof (uint32_t)) {
 		        LEAVE();
 			return 0;
@@ -807,6 +808,7 @@ static int load_ev_tracking_barrier(void)
 			log_printf(LOGSYS_LEVEL_WARNING,
 				   "Unable to write to %s", filename);
 		}
+		close(ev_tracking_fd);
 		LEAVE();
 		return 0;
 	}

+ 7 - 3
lib/cfg.c

@@ -310,6 +310,10 @@ corosync_cfg_ring_status_get (
 		&res_lib_cfg_ringstatusget,
 		sizeof (struct res_lib_cfg_ringstatusget), CS_IPC_TIMEOUT_MS));
 
+	if (error != CS_OK) {
+		goto exit_handle_put;
+	}
+
 	*interface_count = res_lib_cfg_ringstatusget.interface_count;
 	*interface_names = malloc (sizeof (char *) * *interface_count);
 	if (*interface_names == NULL) {
@@ -339,7 +343,7 @@ corosync_cfg_ring_status_get (
 			goto error_free_status;
 		}
 	}
-	goto no_error;
+	goto exit_handle_put;
 
 error_free_status:
 	for (j = 0; j < i; j++) {
@@ -351,13 +355,13 @@ error_free_interface_names:
 	for (j = 0; j < i; j++) {
 		free ((*(interface_names))[j]);
 	}
-	
+
 	free (*status);
 
 error_free_interface_names_array:
 	free (*interface_names);
 
-no_error:
+exit_handle_put:
 	(void)hdb_handle_put (&cfg_hdb, cfg_handle);
 
 	return (error);

+ 2 - 0
lib/cpg.c

@@ -872,6 +872,8 @@ retry_write:
 
 	res = close (fd);
 	if (res) {
+		munmap(addr, bytes);
+
 		return (-1);
 	}
 	*buf = addr;

+ 4 - 0
test/cpgbound.c

@@ -118,6 +118,10 @@ try_again_one:
 		msg_size += 1;
 		printf ("msg size %d\n", msg_size);
 		result = cpg_dispatch (handle, CS_DISPATCH_ALL);
+		if (result != CS_OK && result != CS_ERR_TRY_AGAIN) {
+			printf ("cpg_dispatch failed with result %d\n", res);
+			exit (1);
+		}
 	}
 
 	cpg_finalize (handle);

+ 6 - 1
test/cpghum.c

@@ -307,6 +307,11 @@ int main (int argc, char *argv[]) {
 			}
 			break;
 		case 'n':
+			if (strlen(optarg) >= CPG_MAX_NAME_LENGTH) {
+				fprintf(stderr, "CPG name too long\n");
+				exit(1);
+			}
+
 			strcpy(group_name.value, optarg);
 			group_name.length = strlen(group_name.value);
 			break;
@@ -376,7 +381,7 @@ int main (int argc, char *argv[]) {
 	}
 
 	if (listen_only) {
-		int secs;
+		int secs = 0;
 		if (!quiet) {
 			printf("-- Listening on CPG %s\n", group_name.value);
 			printf("-- Ignore any starting \"counters don't match\" error while we catch up\n");

+ 4 - 0
test/cpgverify.c

@@ -180,6 +180,10 @@ try_again_one:
 			goto try_again_one;
 		}
 		result = cpg_dispatch (handle, CS_DISPATCH_ALL);
+		if (result != CS_OK && result != CS_ERR_TRY_AGAIN) {
+			printf("cpg_dispatch failed with result %d\n", result);
+			exit(1);
+		}
 		i++;
 	} while (run_forever || i < iter);
 

+ 1 - 4
test/testsam.c

@@ -1190,10 +1190,7 @@ static int test9 (pid_t pid, pid_t old_pid, int test_n) {
 
 		if (instance_id == 3) {
 			printf ("%s iid %d: mark failed\n", __FUNCTION__, instance_id);
-			if (err != CS_OK) {
-				fprintf (stderr, "Can't start hc. Error %d\n", err);
-				return 2;
-			}
+
 			err = sam_mark_failed ();
 			if (err != CS_OK) {
 				fprintf (stderr, "Can't mark failed. Error %d\n", err);

+ 9 - 0
tools/corosync-cfgtool.c

@@ -112,7 +112,15 @@ static int ringstatusget_do (char *interface_name)
 				}
 			}
 		}
+
+		for (i = 0; i < interface_count; i++) {
+			free(interface_status[i]);
+			free(interface_names[i]);
+		}
+		free(interface_status);
+		free(interface_names);
 	}
+
 	(void)corosync_cfg_finalize (handle);
 	return rc;
 }
@@ -279,6 +287,7 @@ int main (int argc, char *argv[]) {
 		switch (opt) {
 		case 'i':
 			strncpy(interface_name, optarg, sizeof(interface_name));
+			interface_name[sizeof(interface_name) - 1] = '\0';
 			break;
 		case 's':
 			rc = ringstatusget_do (interface_name);