From mboxrd@z Thu Jan 1 00:00:00 1970 From: Fabio M. Di Nitto Date: Wed, 23 Nov 2011 11:15:24 +0100 Subject: [Cluster-devel] [PATCH 05/41] libcman: correctly check for vars before using them In-Reply-To: <1322043360-17037-1-git-send-email-fdinitto@redhat.com> References: <1322043360-17037-1-git-send-email-fdinitto@redhat.com> Message-ID: List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Spotted by Coverity Scan Signed-off-by: Fabio M. Di Nitto --- :100644 100644 5b015f0... ae6c709... M cman/lib/libcman.c cman/lib/libcman.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cman/lib/libcman.c b/cman/lib/libcman.c index 5b015f0..ae6c709 100644 --- a/cman/lib/libcman.c +++ b/cman/lib/libcman.c @@ -1018,12 +1018,6 @@ static int cman_set_quorum_device(cman_handle_t handle, char buf[strlen(name)+1 + sizeof(int)]; VALIDATE_HANDLE(h); - if ((!name) || (strlen(name) > MAX_CLUSTER_MEMBER_NAME_LEN) || (votes < 0)) - { - errno = EINVAL; - return -1; - } - memcpy(buf, &votes, sizeof(int)); strcpy(buf+sizeof(int), name); return info_call(h, ops, buf, strlen(name)+1+sizeof(int), NULL, 0); @@ -1031,6 +1025,11 @@ static int cman_set_quorum_device(cman_handle_t handle, int cman_register_quorum_device(cman_handle_t handle, char *name, int votes) { + if ((!name) || (strlen(name) > MAX_CLUSTER_MEMBER_NAME_LEN) || (votes < 0)) + { + errno = EINVAL; + return -1; + } return cman_set_quorum_device(handle, CMAN_CMD_REG_QUORUMDEV, name, votes); } @@ -1069,6 +1068,11 @@ int cman_get_quorum_device(cman_handle_t handle, struct cman_qdev_info *info) int cman_update_quorum_device(cman_handle_t handle, char *name, int votes) { + if ((!name) || (strlen(name) > MAX_CLUSTER_MEMBER_NAME_LEN) || (votes < 0)) + { + errno = EINVAL; + return -1; + } return cman_set_quorum_device(handle, CMAN_CMD_UPDATE_QUORUMDEV, name, votes); } -- 1.7.4.4