From: W.C.A. Wijngaards Date: Fri, 18 Jun 2021 16:12:26 +0000 (+0200) Subject: - Fix a number of warnings reported by the gcc analyzer. X-Git-Tag: release-1.13.2rc1~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79209823ac7431dcbebecb0ba564f0f54461269d;p=thirdparty%2Funbound.git - Fix a number of warnings reported by the gcc analyzer. --- diff --git a/doc/Changelog b/doc/Changelog index 3e12c6433..e350b8b3f 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +18 June 2021: Wouter + - Fix a number of warnings reported by the gcc analyzer. + 15 June 2021: George - Merge #440 by kimheino: Various fixes to contrib/unbound_munin_ file. diff --git a/iterator/iter_utils.c b/iterator/iter_utils.c index adc611f73..668f898eb 100644 --- a/iterator/iter_utils.c +++ b/iterator/iter_utils.c @@ -440,6 +440,7 @@ iter_filter_order(struct iter_env* iter_env, struct module_env* env, prev = NULL; a = dp->result_list; for(i = 0; i < got_num; i++) { + if(!a) break; /* robustness */ swap_to_front = 0; if(a->addr.ss_family != AF_INET6 && attempt == -1) { /* if we only have ip4 at low attempt count, @@ -497,6 +498,7 @@ iter_filter_order(struct iter_env* iter_env, struct module_env* env, prev = NULL; a = dp->result_list; for(i = 0; i < got_num; i++) { + if(!a) break; /* robustness */ swap_to_front = 0; if(a->addr.ss_family != AF_INET && attempt == -1) { /* if we only have ip6 at low attempt count, diff --git a/pythonmod/interface.i b/pythonmod/interface.i index 5dae04aa4..ce7dcde71 100644 --- a/pythonmod/interface.i +++ b/pythonmod/interface.i @@ -1546,7 +1546,7 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, { PyObject *func, *py_edns, *py_qstate, *py_opt_list_out, *py_qinfo; PyObject *py_rep, *py_repinfo, *py_region; - PyObject *py_args, *py_kwargs, *result; + PyObject *py_args = NULL, *py_kwargs = NULL, *result = NULL; int res = 0; double py_start_time = ((double)start_time->tv_sec) + ((double)start_time->tv_usec) / 1.0e6; @@ -1561,11 +1561,20 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, py_rep = SWIG_NewPointerObj((void*) rep, SWIGTYPE_p_reply_info, 0); py_repinfo = SWIG_NewPointerObj((void*) repinfo, SWIGTYPE_p_comm_reply, 0); py_region = SWIG_NewPointerObj((void*) region, SWIGTYPE_p_regional, 0); - py_args = Py_BuildValue("(OOOiOOO)", py_qinfo, py_qstate, py_rep, - rcode, py_edns, py_opt_list_out, py_region); - py_kwargs = Py_BuildValue("{s:O,s:d}", "repinfo", py_repinfo, "start_time", - py_start_time); - result = PyObject_Call(func, py_args, py_kwargs); + if(py_qinfo && py_qstate && py_rep && py_edns && py_opt_list_out + && py_region && py_repinfo) { + py_args = Py_BuildValue("(OOOiOOO)", py_qinfo, py_qstate, py_rep, + rcode, py_edns, py_opt_list_out, py_region); + py_kwargs = Py_BuildValue("{s:O,s:d}", "repinfo", py_repinfo, "start_time", + py_start_time); + if(py_args && py_kwargs) { + result = PyObject_Call(func, py_args, py_kwargs); + } else { + log_err("pythonmod: malloc failure in python_inplace_cb_reply_generic"); + } + } else { + log_err("pythonmod: malloc failure in python_inplace_cb_reply_generic"); + } Py_XDECREF(py_edns); Py_XDECREF(py_qstate); Py_XDECREF(py_opt_list_out); @@ -1624,6 +1633,7 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, { int res = 0; PyObject *func = python_callback; + PyObject *py_args = NULL, *py_kwargs = NULL, *result = NULL; PyGILState_STATE gstate = PyGILState_Ensure(); @@ -1632,12 +1642,19 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, PyObject *py_addr = SWIG_NewPointerObj((void *) addr, SWIGTYPE_p_sockaddr_storage, 0); PyObject *py_zone = PyBytes_FromStringAndSize((const char *)zone, zonelen); PyObject *py_region = SWIG_NewPointerObj((void*) region, SWIGTYPE_p_regional, 0); - - PyObject *py_args = Py_BuildValue("(OiOOOO)", py_qinfo, flags, py_qstate, py_addr, py_zone, py_region); - PyObject *py_kwargs = Py_BuildValue("{}"); - PyObject *result = PyObject_Call(func, py_args, py_kwargs); - if (result) { - res = PyInt_AsLong(result); + if(py_qinfo && py_qstate && py_addr && py_zone && py_region) { + py_args = Py_BuildValue("(OiOOOO)", py_qinfo, flags, py_qstate, py_addr, py_zone, py_region); + py_kwargs = Py_BuildValue("{}"); + if(py_args && py_kwargs) { + result = PyObject_Call(func, py_args, py_kwargs); + if (result) { + res = PyInt_AsLong(result); + } + } else { + log_err("pythonmod: malloc failure in python_inplace_cb_query_generic"); + } + } else { + log_err("pythonmod: malloc failure in python_inplace_cb_query_generic"); } Py_XDECREF(py_qinfo); diff --git a/pythonmod/pythonmod.c b/pythonmod/pythonmod.c index 6e60d02fe..0bbdeeb6b 100644 --- a/pythonmod/pythonmod.c +++ b/pythonmod/pythonmod.c @@ -561,9 +561,19 @@ void pythonmod_operate(struct module_qstate* qstate, enum module_ev event, { /* create qstate */ pq = qstate->minfo[id] = malloc(sizeof(struct pythonmod_qstate)); + if(!pq) { + log_err("pythonmod_operate: malloc failure for qstate"); + PyGILState_Release(gil); + return; + } /* Initialize per query data */ pq->data = PyDict_New(); + if(!pq->data) { + log_err("pythonmod_operate: malloc failure for query data dict"); + PyGILState_Release(gil); + return; + } } /* Call operate */ diff --git a/services/authzone.c b/services/authzone.c index 9ebd79ed3..0f9879ce7 100644 --- a/services/authzone.c +++ b/services/authzone.c @@ -7168,12 +7168,14 @@ xfer_set_masters(struct auth_master** list, struct config_auth* c, if(with_http) for(p = c->urls; p; p = p->next) { m = auth_master_new(&list); + if(!m) return 0; m->http = 1; if(!parse_url(p->str, &m->host, &m->file, &m->port, &m->ssl)) return 0; } for(p = c->masters; p; p = p->next) { m = auth_master_new(&list); + if(!m) return 0; m->ixfr = 1; /* this flag is not configurable */ m->host = strdup(p->str); if(!m->host) { @@ -7183,6 +7185,7 @@ xfer_set_masters(struct auth_master** list, struct config_auth* c, } for(p = c->allow_notify; p; p = p->next) { m = auth_master_new(&list); + if(!m) return 0; m->allow_notify = 1; m->host = strdup(p->str); if(!m->host) { diff --git a/services/cache/infra.c b/services/cache/infra.c index 2d16bcd6e..518e69622 100644 --- a/services/cache/infra.c +++ b/services/cache/infra.c @@ -236,6 +236,9 @@ infra_create(struct config_file* cfg) sizeof(struct infra_cache)); size_t maxmem = cfg->infra_cache_numhosts * (sizeof(struct infra_key)+ sizeof(struct infra_data)+INFRA_BYTES_NAME); + if(!infra) { + return NULL; + } infra->hosts = slabhash_create(cfg->infra_cache_slabs, INFRA_HOST_STARTSIZE, maxmem, &infra_sizefunc, &infra_compfunc, &infra_delkeyfunc, &infra_deldatafunc, NULL); diff --git a/util/data/msgreply.c b/util/data/msgreply.c index 48550cbe4..00272fd1c 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -329,7 +329,10 @@ parse_create_rrset(sldns_buffer* pkt, struct rrset_parse* pset, return 0; /* copy & decompress */ if(!parse_rr_copy(pkt, pset, *data)) { - if(!region) free(*data); + if(!region) { + free(*data); + *data = NULL; + } return 0; } return 1; @@ -394,8 +397,13 @@ parse_copy_decompress_rrset(sldns_buffer* pkt, struct msg_parse* msg, pk->rk.type = htons(pset->type); pk->rk.rrset_class = pset->rrset_class; /** read data part. */ - if(!parse_create_rrset(pkt, pset, &data, region)) + if(!parse_create_rrset(pkt, pset, &data, region)) { + if(!region) { + free(pk->rk.dname); + pk->rk.dname = NULL; + } return 0; + } pk->entry.data = (void*)data; pk->entry.key = (void*)pk; pk->entry.hash = pset->hash; diff --git a/util/shm_side/shm_main.c b/util/shm_side/shm_main.c index af8c5bcf3..51039abf3 100644 --- a/util/shm_side/shm_main.c +++ b/util/shm_side/shm_main.c @@ -130,6 +130,7 @@ int shm_main_init(struct daemon* daemon) /* Just release memory unused */ free(daemon->shm_info); + daemon->shm_info = NULL; return 0; } @@ -143,6 +144,7 @@ int shm_main_init(struct daemon* daemon) /* Just release memory unused */ free(daemon->shm_info); + daemon->shm_info = NULL; return 0; } @@ -156,6 +158,7 @@ int shm_main_init(struct daemon* daemon) /* Just release memory unused */ free(daemon->shm_info); + daemon->shm_info = NULL; return 0; } @@ -170,6 +173,7 @@ int shm_main_init(struct daemon* daemon) /* Just release memory unused */ free(daemon->shm_info); + daemon->shm_info = NULL; return 0; } @@ -210,6 +214,8 @@ void shm_main_shutdown(struct daemon* daemon) if (daemon->shm_info->ptr_arr) shmdt(daemon->shm_info->ptr_arr); + free(daemon->shm_info); + daemon->shm_info = NULL; #else (void)daemon; #endif /* HAVE_SHMGET */ diff --git a/validator/val_nsec.c b/validator/val_nsec.c index 032d2ae03..a4e5b3137 100644 --- a/validator/val_nsec.c +++ b/validator/val_nsec.c @@ -180,6 +180,7 @@ nsec_verify_rrset(struct module_env* env, struct val_env* ve, { struct packed_rrset_data* d = (struct packed_rrset_data*) nsec->entry.data; + if(!d) return 0; if(d->security == sec_status_secure) return 1; rrset_check_sec_status(env->rrset_cache, nsec, *env->now);