소스 검색

qdevice: mv free(str) after port validation

in the previous code of qdevice_net_instance_init_from_cmap:
   host_port = strtol(str, &ep, 10);

   free(str);

   if (host_port <= 0 || host_port > ((uint16_t)~0) || *ep != '\0')

before free, *ep is '\0'. But after free, *ep changed to 'U', so mv
free behind the comparison.

Signed-off-by: Bin Liu <bliu@suse.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
(cherry picked from commit d624ea4149ca3539f8b6b9965c75f6c25596d964)
Bin Liu 8 년 전
부모
커밋
ff338873ac
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      qdevices/qdevice-net-instance.c

+ 2 - 2
qdevices/qdevice-net-instance.c

@@ -274,12 +274,12 @@ qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance)
 	if (cmap_get_string(cmap_handle, "quorum.device.net.port", &str) == CS_OK) {
 	if (cmap_get_string(cmap_handle, "quorum.device.net.port", &str) == CS_OK) {
 		host_port = strtol(str, &ep, 10);
 		host_port = strtol(str, &ep, 10);
 
 
-		free(str);
-
 		if (host_port <= 0 || host_port > ((uint16_t)~0) || *ep != '\0') {
 		if (host_port <= 0 || host_port > ((uint16_t)~0) || *ep != '\0') {
 			qdevice_log(LOG_ERR, "quorum.device.net.port must be in range 0-65535");
 			qdevice_log(LOG_ERR, "quorum.device.net.port must be in range 0-65535");
+			free(str);
 			goto error_free_host_addr;
 			goto error_free_host_addr;
 		}
 		}
+		free(str);
 	} else {
 	} else {
 		host_port = QNETD_DEFAULT_HOST_PORT;
 		host_port = QNETD_DEFAULT_HOST_PORT;
 	}
 	}