diff options
author | Shawn Routhier <sar@isc.org> | 2012-10-16 15:05:24 -0700 |
---|---|---|
committer | Shawn Routhier <sar@isc.org> | 2012-10-16 15:05:24 -0700 |
commit | 0f750c4fb19823f622cfde356ac7f7aa2c9a3427 (patch) | |
tree | fea3ccc473e35832e12a0a3d0a576ea9b2174846 /omapip | |
parent | 881442e20f455fb1dc21600390cc5aecae08fd72 (diff) | |
download | isc-dhcp-0f750c4fb19823f622cfde356ac7f7aa2c9a3427.tar.gz |
[master]
[rt23833]
Clean up a number of items identified by the Coverity
static analysis tool. Runs courtesy of Red Hat.
Diffstat (limited to 'omapip')
-rw-r--r-- | omapip/buffer.c | 7 | ||||
-rw-r--r-- | omapip/connection.c | 31 | ||||
-rw-r--r-- | omapip/listener.c | 9 | ||||
-rw-r--r-- | omapip/protocol.c | 21 | ||||
-rw-r--r-- | omapip/support.c | 11 | ||||
-rw-r--r-- | omapip/trace.c | 15 |
6 files changed, 60 insertions, 34 deletions
diff --git a/omapip/buffer.c b/omapip/buffer.c index 4efff9f4..4104cfb7 100644 --- a/omapip/buffer.c +++ b/omapip/buffer.c @@ -3,7 +3,8 @@ Buffer access functions for the object management protocol... */ /* - * Copyright (c) 2004,2005,2007,2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2009,2012 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2005,2007 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999-2003 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any @@ -279,9 +280,7 @@ isc_result_t omapi_connection_copyin (omapi_object_t *h, int sig_flags = SIG_MODE_UPDATE; omapi_connection_object_t *c; - /* Make sure len is valid. */ - if (len < 0) - return DHCP_R_INVALIDARG; + /* no need to verify len as it's unsigned */ if (!h || h -> type != omapi_type_connection) return DHCP_R_INVALIDARG; c = (omapi_connection_object_t *)h; diff --git a/omapip/connection.c b/omapip/connection.c index a9199683..d08524d2 100644 --- a/omapip/connection.c +++ b/omapip/connection.c @@ -3,7 +3,7 @@ Subroutines for dealing with connections. */ /* - * Copyright (c) 2009-2011 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2009-2012 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999-2003 by Internet Software Consortium * @@ -396,22 +396,23 @@ static void trace_connect_input (trace_type_t *ttype, /* Find the matching connect object, if there is one. */ omapi_array_foreach_begin (omapi_connections, omapi_connection_object_t, lp) { - for (i = 0; (lp -> connect_list && - i < lp -> connect_list -> count); i++) { + for (i = 0; (lp->connect_list && + i < lp->connect_list->count); i++) { if (!memcmp (&remote.sin_addr, - &lp -> connect_list -> addresses [i].address, + &lp->connect_list->addresses[i].address, sizeof remote.sin_addr) && (ntohs (remote.sin_port) == - lp -> connect_list -> addresses [i].port)) - lp -> state = omapi_connection_connected; - lp -> remote_addr = remote; - lp -> remote_addr.sin_family = AF_INET; - omapi_addr_list_dereference (&lp -> connect_list, MDL); - lp -> index = connect_index; - status = omapi_signal_in ((omapi_object_t *)lp, - "connect"); - omapi_connection_dereference (&lp, MDL); - return; + lp->connect_list->addresses[i].port)) { + lp->state = omapi_connection_connected; + lp->remote_addr = remote; + lp->remote_addr.sin_family = AF_INET; + omapi_addr_list_dereference(&lp->connect_list, MDL); + lp->index = connect_index; + status = omapi_signal_in((omapi_object_t *)lp, + "connect"); + omapi_connection_dereference (&lp, MDL); + return; + } } } omapi_array_foreach_end (omapi_connections, omapi_connection_object_t, lp); @@ -628,7 +629,7 @@ isc_result_t omapi_connection_connect (omapi_object_t *h) static isc_result_t omapi_connection_connect_internal (omapi_object_t *h) { - int error; + int error = 0; omapi_connection_object_t *c; socklen_t sl; isc_result_t status; diff --git a/omapip/listener.c b/omapip/listener.c index 30259eb6..138b0f23 100644 --- a/omapip/listener.c +++ b/omapip/listener.c @@ -84,7 +84,14 @@ isc_result_t omapi_listen_addr (omapi_object_t *h, obj = (omapi_listener_object_t *)0; status = omapi_listener_allocate (&obj, MDL); if (status != ISC_R_SUCCESS) - return status; + /* + * we could simply return here but by going to + * error_exit we keep the code check tools happy + * without removing the NULL check on obj at + * the exit, which we could skip curently but + * might want in the future. + */ + goto error_exit; obj->socket = -1; /* Connect this object to the inner object. */ diff --git a/omapip/protocol.c b/omapip/protocol.c index 99064898..112bf128 100644 --- a/omapip/protocol.c +++ b/omapip/protocol.c @@ -354,7 +354,7 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h, omapi_protocol_object_t *p; omapi_object_t *c; omapi_message_object_t *m; - omapi_value_t *signature; + omapi_value_t *signature = NULL; u_int16_t nlen; u_int32_t vlen; u_int32_t th; @@ -680,7 +680,6 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h, case omapi_protocol_signature_wait: if (p -> message -> id_object) { /* Compute the signature of the message. */ - signature = (omapi_value_t *)0; status = omapi_get_value_str (c, (omapi_object_t *)0, "input-signature", &signature); @@ -707,7 +706,9 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h, p -> message -> authlen); if (status != ISC_R_SUCCESS) { - omapi_value_dereference (&signature, MDL); + if (signature != NULL) { + omapi_value_dereference (&signature, MDL); + } omapi_disconnect (c, 1); return ISC_R_NOMEMORY; } @@ -726,7 +727,9 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h, p->verify_result = DHCP_R_INVALIDKEY; } - omapi_value_dereference (&signature, MDL); + if (signature != NULL) { + omapi_value_dereference (&signature, MDL); + } /* Process the message. */ message_done: @@ -860,10 +863,10 @@ isc_result_t omapi_protocol_set_value (omapi_object_t *h, p = (omapi_protocol_object_t *)h; if (omapi_ds_strcmp (name, "default-authenticator") == 0) { - if (value -> type != omapi_datatype_object) + if (!value || value -> type != omapi_datatype_object) return DHCP_R_INVALIDARG; - if (!value || !value -> u.object) { + if (!value -> u.object) { p -> default_auth = (omapi_remote_auth_t *)0; } else { for (r = p -> remote_auth_list; r; r = r -> next) @@ -987,7 +990,11 @@ isc_result_t omapi_protocol_configure_security (omapi_object_t *h, l -> verify_auth = verify_auth; l -> insecure = 0; - return omapi_listener_configure_security (h -> outer, verify_addr); + if (h -> outer != NULL) { + return omapi_listener_configure_security (h -> outer, verify_addr); + } else { + return DHCP_R_INVALIDARG; + } } diff --git a/omapip/support.c b/omapip/support.c index c82dcc8c..7768c6e6 100644 --- a/omapip/support.c +++ b/omapip/support.c @@ -3,7 +3,8 @@ Subroutines providing general support for objects. */ /* - * Copyright (c) 2004-2007,2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2009,2012 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999-2003 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any @@ -551,8 +552,14 @@ isc_result_t omapi_object_update (omapi_object_t *obj, omapi_object_t *id, if (status != ISC_R_SUCCESS && status != DHCP_R_UNCHANGED) return status; } + + /* + * For now ignore the return value. I'm not sure if we want to + * generate an error if we can't set the handle value. If we + * do add a check we probably should allow unchanged and notfound + */ if (handle) - omapi_set_int_value (obj, id, "remote-handle", (int)handle); + (void) omapi_set_int_value (obj, id, "remote-handle", (int)handle); status = omapi_signal (obj, "updated"); if (status != ISC_R_NOTFOUND) return status; diff --git a/omapip/trace.c b/omapip/trace.c index 9fd3fb5e..8e203cd4 100644 --- a/omapip/trace.c +++ b/omapip/trace.c @@ -5,6 +5,7 @@ transactions... */ /* + * Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2001-2003 by Internet Software Consortium @@ -235,6 +236,7 @@ isc_result_t trace_write_packet_iov (trace_type_t *ttype, /* We have to swap out the data, because it may be read back on a machine of different endianness. */ + memset(&tmp, 0, sizeof(tmp)); tmp.type_index = htonl (ttype -> index); tmp.when = htonl (time ((time_t *)0)); /* XXX */ tmp.length = htonl (length); @@ -690,27 +692,30 @@ isc_result_t trace_get_file (trace_type_t *ttype, } result = trace_get_next_packet (&ttype, tpkt, buf, len, &max); + /* done with tpkt, free it */ + dfree (tpkt, MDL); if (result != ISC_R_SUCCESS) { - dfree (tpkt, MDL); - if (*buf) + if (*buf) { dfree (*buf, MDL); + *buf = NULL; + } return result; } /* Make sure the filename is right. */ if (strcmp (filename, *buf)) { log_error ("Read file %s when expecting %s", *buf, filename); + dfree (*buf, MDL); + *buf = NULL; + status = fsetpos (traceinfile, &curpos); if (status < 0) { log_error ("fsetpos in tracefile failed: %m"); - dfree (tpkt, MDL); - dfree (*buf, MDL); return DHCP_R_PROTOCOLERROR; } return ISC_R_UNEXPECTEDTOKEN; } - dfree (tpkt, MDL); return ISC_R_SUCCESS; } #endif /* TRACING */ |