From: Nikos Mavrogiannopoulos Date: Sun, 21 Aug 2011 17:41:43 +0000 (+0200) Subject: Handle memory allocation errors. X-Git-Tag: gnutls_3_0_2~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df1778a638d45bda2539299948ef0ebfd6b407a6;p=thirdparty%2Fgnutls.git Handle memory allocation errors. --- diff --git a/src/crywrap/crywrap.c b/src/crywrap/crywrap.c index bdf4e0f77d..1c51d632f0 100644 --- a/src/crywrap/crywrap.c +++ b/src/crywrap/crywrap.c @@ -280,6 +280,11 @@ _crywrap_addr_get (const char *hostname, struct sockaddr_storage **addr) hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_IP; *addr = calloc (1, sizeof (struct sockaddr_storage)); + if (*addr == NULL) + { + free(lz); + return -1; + } if (getaddrinfo (lz, NULL, &hints, &res) != 0) { @@ -485,6 +490,9 @@ _crywrap_config_parse (int argc, char **argv) crywrap_config_t *config = (crywrap_config_t *)malloc (sizeof (crywrap_config_t)); + if (config == NULL) + return NULL; + config->listen.port = 0; config->listen.addr = NULL; config->dest.port = 0; @@ -641,6 +649,9 @@ _crywrap_listen (const crywrap_config_t *config) int ret; cur = calloc (1, sizeof (struct addrinfo)); + if (cur == NULL) + return -1; + cur->ai_family = config->listen.addr->ss_family; switch (cur->ai_family) @@ -654,6 +665,9 @@ _crywrap_listen (const crywrap_config_t *config) } cur->ai_addr = malloc (cur->ai_addrlen); + if (cur->ai_addr == NULL) + return -1; + memcpy (cur->ai_addr, config->listen.addr, cur->ai_addrlen); ret = _crywrap_bind (cur, htons (config->listen.port)); @@ -679,6 +693,9 @@ _crywrap_remote_connect (const struct sockaddr_storage *addr, int port) int sock; cur = calloc (1, sizeof (struct addrinfo)); + if (cur == NULL) + return -1; + cur->ai_family = addr->ss_family; switch (cur->ai_family) @@ -692,6 +709,9 @@ _crywrap_remote_connect (const struct sockaddr_storage *addr, int port) } cur->ai_addr = malloc (cur->ai_addrlen); + if (cur->ai_addr == NULL) + return -1; + memcpy (cur->ai_addr, addr, cur->ai_addrlen); switch (cur->ai_family)