From: Jim Meyering Date: Tue, 23 Jun 2009 13:44:10 +0200 Subject: [Cluster-devel] [PATCH cluster 5/5] cman: handle malloc failure (i.e., don't deref NULL) In-Reply-To: <1245757450-13840-1-git-send-email-jim@meyering.net> References: <1245757450-13840-1-git-send-email-jim@meyering.net> Message-ID: <1245757450-13840-6-git-send-email-jim@meyering.net> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit From: Jim Meyering * cman/daemon/commands.c (do_cmd_get_extrainfo): Handle malloc failure (i.e., don't deref NULL). (do_cmd_get_all_members): Likewise. --- cman/daemon/commands.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/cman/daemon/commands.c b/cman/daemon/commands.c index b343bcb..c360909 100644 --- a/cman/daemon/commands.c +++ b/cman/daemon/commands.c @@ -538,6 +538,8 @@ static int do_cmd_get_extrainfo(char *cmdbuf, char **retbuf, int retsize, int *r sizeof(struct sockaddr_storage) * (MAX_INTERFACES*2))) { *retbuf = malloc(sizeof(struct cl_extra_info) + sizeof(struct sockaddr_storage) * (MAX_INTERFACES*2)); + if (*retbuf == NULL) + return -ENOMEM; outbuf = *retbuf + offset; einfo = (struct cl_extra_info *)outbuf; @@ -635,6 +637,8 @@ static int do_cmd_get_all_members(char *cmdbuf, char **retbuf, int retsize, int /* If there is not enough space in the default buffer, allocate some more. */ if ((retsize / sizeof(struct cl_cluster_node)) < total_nodes) { *retbuf = malloc(sizeof(struct cl_cluster_node) * total_nodes + offset); + if (!*retbuf) + return -ENOMEM; outbuf = *retbuf + offset; log_printf(LOGSYS_LEVEL_DEBUG, "memb: get_all_members: allocated new buffer (retsize=%d)\n", retsize); } -- 1.6.3.3.420.gd4b46