Fixes for NULL test for function returns such as malloc() - as reported by Coverity

This commit is contained in:
Mark Riddoch
2013-08-29 13:34:21 +02:00
parent 03725cabe3
commit a445b6ff37
4 changed files with 32 additions and 9 deletions

View File

@ -410,7 +410,8 @@ SERVER *server;
{
char *user = config_get_value(obj->parameters, "user");
char *auth = config_get_value(obj->parameters, "auth");
service_update(service, router, user, auth);
if (user && auth)
service_update(service, router, user, auth);
obj->element = service;
}
else

View File

@ -48,8 +48,14 @@ void
bitmask_init(GWBITMASK *bitmask)
{
bitmask->length = BIT_LENGTH_INITIAL;
bitmask->bits = malloc(bitmask->length / 8);
memset(bitmask->bits, 0, bitmask->length / 8);
if ((bitmask->bits = malloc(bitmask->length / 8)) == NULL)
{
bitmask->length = 0;
}
else
{
memset(bitmask->bits, 0, bitmask->length / 8);
}
spinlock_init(&bitmask->lock);
}
@ -196,9 +202,15 @@ bitmask_copy(GWBITMASK *dest, GWBITMASK *src)
spinlock_acquire(&dest->lock);
if (dest->length)
free(dest->bits);
dest->bits = malloc(src->length / 8);
dest->length = src->length;
memcpy(dest->bits, src->bits, src->length / 8);
if ((dest->bits = malloc(src->length / 8)) == NULL)
{
dest->length = 0;
}
else
{
dest->length = src->length;
memcpy(dest->bits, src->bits, src->length / 8);
}
spinlock_release(&dest->lock);
spinlock_release(&src->lock);
}

View File

@ -564,7 +564,8 @@ static int gw_change_user(DCB *backend, SERVER *server, SESSION *in_session, GWB
// allocate memory for token only if auth_token_len > 0
if (auth_token_len) {
auth_token = (uint8_t *)malloc(auth_token_len);
if ((auth_token = (uint8_t *)malloc(auth_token_len)) == NULL)
return rv;
memcpy(auth_token, client_auth_packet, auth_token_len);
client_auth_packet += auth_token_len;
}

View File

@ -257,6 +257,7 @@ telnetd_hangup(DCB *dcb)
* socket for the protocol.
*
* @param dcb The descriptor control block
* @return The number of new connections created
*/
static int
telnetd_accept(DCB *dcb)
@ -275,17 +276,25 @@ int n_connect = 0;
else
{
atomic_add(&dcb->stats.n_accepts, 1);
client = dcb_alloc();
if ((client = dcb_alloc()) == NULL)
{
return n_connect;
}
client->fd = so;
client->remote = strdup(inet_ntoa(addr.sin_addr));
memcpy(&client->func, &MyObject, sizeof(GWPROTOCOL));
client->session = session_alloc(dcb->session->service, client);
client->state = DCB_STATE_IDLE;
client->protocol = malloc(sizeof(TELNETD));
if ((client->protocol = malloc(sizeof(TELNETD))) == NULL)
{
dcb_free(client);
return n_connect;
}
if (poll_add_dcb(client) == -1)
{
dcb_free(client);
return n_connect;
}
n_connect++;