autofs-5.0.6 - code analysis fixes 1 From: Ian Kent Code analysis defect fixes, installment 1. - fix signed usage of unsigned variable in do_srv_query(). - make NULL check handling of variable dcs explicit in get_dc_list(). - adding an explicit NULL check for variable dcs gaurds against future changes in get_srv_rrs() returning success while not clearing the dcs variable. - makes it explict for readers why we don't need to check for NULL before free later in the loop. - fix typo in do_reconnect() - uri is never set now and, at this point, we need to try to connect to the last server uri (ctxt->uri->uri) which is set in find_server() when ctxt->uri is NULL. --- CHANGELOG | 1 + modules/dclist.c | 11 +++++------ modules/lookup_ldap.c | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d7c20ca..3aa5f3d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ - fix result null check in read_one_map(). - fix LDAP result leaks on error paths. - fix fix LDAP result leaks on error paths. +- code analysis fixes part 1. 28/06/2011 autofs-5.0.6 ----------------------- diff --git a/modules/dclist.c b/modules/dclist.c index aeb107f..d16b913 100644 --- a/modules/dclist.c +++ b/modules/dclist.c @@ -69,7 +69,7 @@ static void dclist_mutex_unlock(void) static int do_srv_query(unsigned int logopt, char *name, u_char **packet) { - unsigned int len = PACKETSZ; + int len = PACKETSZ; unsigned int last_len = len; char ebuf[MAX_ERR_BUF]; u_char *buf; @@ -500,7 +500,8 @@ struct dclist *get_dc_list(unsigned int logopt, const char *uri) } dclist_mutex_lock(); - if (!get_srv_rrs(logopt, request, &dcs, &numdcs)) { + ret = get_srv_rrs(logopt, request, &dcs, &numdcs); + if (!ret | !dcs) { error(logopt, "DNS SRV query failed for domain %s", domain); dclist_mutex_unlock(); @@ -526,8 +527,7 @@ struct dclist *get_dc_list(unsigned int logopt, const char *uri) if (!tmp) { char *estr = strerror_r(errno, buf, MAX_ERR_BUF); error(logopt, "realloc: %s", estr); - if (dcs) - free_srv_rrs(dcs, numdcs); + free_srv_rrs(dcs, numdcs); goto out_error; } @@ -548,8 +548,7 @@ struct dclist *get_dc_list(unsigned int logopt, const char *uri) if (ret > 6) { error(logopt, "invalid port: %u", dcs[i].port); - if (dcs) - free_srv_rrs(dcs, numdcs); + free_srv_rrs(dcs, numdcs); goto out_error; } strcat(tmp, port); diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c index d8e93e7..b6875fe 100644 --- a/modules/lookup_ldap.c +++ b/modules/lookup_ldap.c @@ -736,7 +736,6 @@ static LDAP *find_server(unsigned logopt, struct lookup_context *ctxt) static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt) { LDAP *ldap = NULL; - char *uri; if (ctxt->server || !ctxt->uris) { ldap = do_connect(logopt, ctxt->server, ctxt); @@ -780,7 +779,7 @@ static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt) */ if (!ldap) { autofs_sasl_dispose(ctxt); - ldap = connect_to_server(logopt, uri, ctxt); + ldap = connect_to_server(logopt, ctxt->uri->uri, ctxt); } #endif if (ldap)