diff --git a/src/context.c b/src/context.c index cc059f6f..c0d8504e 100644 --- a/src/context.c +++ b/src/context.c @@ -2473,7 +2473,8 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context, return GETDNS_RETURN_GOOD; invalid_parameter: - r = GETDNS_RETURN_INVALID_PARAMETER; + _getdns_upstreams_dereference(upstreams); + return GETDNS_RETURN_INVALID_PARAMETER; error: _getdns_upstreams_dereference(upstreams); return GETDNS_RETURN_CONTEXT_UPDATE_FAIL; @@ -3637,7 +3638,7 @@ getdns_context_get_suffix(getdns_context *context, getdns_list **value) else *value = list; - return GETDNS_RETURN_GOOD; + return r; } getdns_return_t diff --git a/src/convert.c b/src/convert.c index 1e0f1027..cf23633f 100644 --- a/src/convert.c +++ b/src/convert.c @@ -240,7 +240,7 @@ getdns_rr_dict2wire( if (r != GETDNS_RETURN_GOOD && r != GETDNS_RETURN_NEED_MORE_SPACE) return r; - if (!(buf = malloc(buf_len))) + if (!(buf = malloc(buf_len ? buf_len : 1))) return GETDNS_RETURN_MEMORY_ERROR; if (!r) @@ -658,11 +658,16 @@ _getdns_wire2msg_dict_scan(struct mem_funcs *mf, result, "question", rr_dict))) goto error; break; - default: + case GLDNS_SECTION_ANSWER: + case GLDNS_SECTION_AUTHORITY: + case GLDNS_SECTION_ADDITIONAL: if ((r = _getdns_list_append_this_dict( sections[section], rr_dict))) goto error; break; + default: + r = GETDNS_RETURN_GENERIC_ERROR; + goto error; } rr_dict = NULL; } @@ -849,7 +854,7 @@ getdns_msg_dict2wire( if (r != GETDNS_RETURN_GOOD && r != GETDNS_RETURN_NEED_MORE_SPACE) return r; - if (!(buf = malloc(buf_len))) + if (!(buf = malloc(buf_len ? buf_len : 1))) return GETDNS_RETURN_MEMORY_ERROR; if (!r) diff --git a/src/dict.c b/src/dict.c index ebd129ca..1f1c9a25 100644 --- a/src/dict.c +++ b/src/dict.c @@ -65,7 +65,7 @@ static char *_json_ptr_first(const struct mem_funcs *mf, if (!(next_ref = strchr(jptr, '/'))) next_ref = strchr(jptr, '\0'); - if (next_ref - jptr > first_sz) + if (next_ref - jptr + 1 > first_sz || !first) first = GETDNS_XMALLOC(*mf, char, next_ref - jptr + 1); for (j = first, k = jptr; k < next_ref; j++, k++) @@ -484,7 +484,6 @@ _getdns_dict_copy(const struct getdns_dict * srcdict, if (!*dstdict) return GETDNS_RETURN_GENERIC_ERROR; - retval = GETDNS_RETURN_GOOD; RBTREE_FOR(item, struct getdns_dict_item *, (struct _getdns_rbtree_t *)&(srcdict->root)) { key = (char *) item->node.key; @@ -508,6 +507,9 @@ _getdns_dict_copy(const struct getdns_dict * srcdict, retval = getdns_dict_set_list(*dstdict, key, item->i.data.list); break; + default: + retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; + break; } if (retval != GETDNS_RETURN_GOOD) { getdns_dict_destroy(*dstdict);; diff --git a/src/dnssec.c b/src/dnssec.c index 9bb95471..093ee40b 100644 --- a/src/dnssec.c +++ b/src/dnssec.c @@ -828,7 +828,7 @@ static chain_head *add_rrset2val_chain(struct mem_funcs *mf, ; node = node->parent, n++); for ( n -= max_labels, node = max_head->parent - ; n + ; n && node ; n--, node = node->parent); max_node = node; @@ -2646,8 +2646,8 @@ static int key_proves_nonexistance( for ( i = rrset_iter_init(&i_spc, rrset->pkt, rrset->pkt_len) ; i ; i = rrset_iter_next(i)) { - if ( (ce = rrset_iter_value(i))->rr_type - != GETDNS_RRTYPE_NSEC3 + if ( !(ce = rrset_iter_value(i)) + || ce->rr_type != GETDNS_RRTYPE_NSEC3 /* Get the bitmap rdata field */ || !(nsec_rr = rrtype_iter_init(&nsec_spc, ce)) diff --git a/src/gldns/keyraw.c b/src/gldns/keyraw.c index 6b4f4481..7a27e7f0 100644 --- a/src/gldns/keyraw.c +++ b/src/gldns/keyraw.c @@ -206,7 +206,6 @@ gldns_key_buf2dsa_raw(unsigned char* key, size_t len) offset += length; Y = BN_bin2bn(key+offset, (int)length, NULL); - offset += length; /* create the key and set its properties */ if(!Q || !P || !G || !Y || !(dsa = DSA_new())) { diff --git a/src/gldns/parseutil.c b/src/gldns/parseutil.c index a21567e0..d68fa89c 100644 --- a/src/gldns/parseutil.c +++ b/src/gldns/parseutil.c @@ -637,7 +637,7 @@ int gldns_b64_ntop(uint8_t const *src, size_t srclength, target[o+1] = b64[ ((src[i]&0x03)<<4) | (src[i+1]>>4) ]; target[o+2] = b64[ ((src[i+1]&0x0f)<<2) ]; target[o+3] = pad64; - i += 2; + /* i += 2; */ o += 4; break; case 1: @@ -646,7 +646,7 @@ int gldns_b64_ntop(uint8_t const *src, size_t srclength, target[o+1] = b64[ ((src[i]&0x03)<<4) ]; target[o+2] = pad64; target[o+3] = pad64; - i += 1; + /* i += 1; */ o += 4; break; case 0: diff --git a/src/gldns/str2wire.c b/src/gldns/str2wire.c index 2ac0e23a..4550a29a 100644 --- a/src/gldns/str2wire.c +++ b/src/gldns/str2wire.c @@ -892,10 +892,10 @@ int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, parse_state?parse_state->default_ttl:0, (parse_state&&parse_state->origin_len)? parse_state->origin:NULL, - parse_state->origin_len, + parse_state?parse_state->origin_len:0, (parse_state&&parse_state->prev_rr_len)? parse_state->prev_rr:NULL, - parse_state->prev_rr_len); + parse_state?parse_state->prev_rr_len:0); } return GLDNS_WIREPARSE_ERR_OK; } diff --git a/src/request-internal.c b/src/request-internal.c index f619429c..a81587f8 100644 --- a/src/request-internal.c +++ b/src/request-internal.c @@ -691,7 +691,7 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop, getdns_dict *add_opt_parameters; int have_add_opt_parameters; - getdns_list *options; + getdns_list *options = NULL; size_t noptions = 0; size_t i; diff --git a/src/test/check_getdns_context_set_timeout.c b/src/test/check_getdns_context_set_timeout.c index b9884fe6..f588445a 100644 --- a/src/test/check_getdns_context_set_timeout.c +++ b/src/test/check_getdns_context_set_timeout.c @@ -206,12 +206,13 @@ void* run_server(void* data) { } getdns_dict_destroy(dns_msg); r = getdns_general_sync(ctxt, qname_str, qtype, NULL, &responses[num_received].reply); - free(qname_str); if (r) { fprintf( stderr, "Could query for \"%s\" %d: \"%s\"\n", qname_str, (int)qtype , getdns_get_errorstr_by_id(r)); + free(qname_str); continue; } + free(qname_str); if ((r = getdns_dict_set_int(responses[num_received].reply, "/replies_tree/0/header/id", qid))) { fprintf( stderr, "Could not set message ID on reply dict: \"%s\"\n" , getdns_get_errorstr_by_id(r)); diff --git a/src/test/check_getdns_transport.c b/src/test/check_getdns_transport.c index aef03e54..7d97c27c 100644 --- a/src/test/check_getdns_transport.c +++ b/src/test/check_getdns_transport.c @@ -29,6 +29,7 @@ #include "check_getdns_transport.h" #include "check_getdns_common.h" #include +#include #include #include #include @@ -111,7 +112,9 @@ void* run_transport_server(void* data) { conn = accept(tcp, (struct sockaddr *) &client_addr, &len); /* throw away the length */ n = read(conn, tcplength, 2); + assert(n == 2); n = read(conn, mesg, 65536); + assert(n == ((tcplength[0] << 8) | tcplength[1])); tcp_count++; } else { fprintf(stderr, "Timeout in run_transport_server\n"); @@ -145,12 +148,13 @@ void* run_transport_server(void* data) { } getdns_dict_destroy(dns_msg); r = getdns_general_sync(ctxt, qname_str, qtype, NULL, &dns_msg); - free(qname_str); if (r) { fprintf( stderr, "Could query for \"%s\" %d: \"%s\"\n", qname_str, (int)qtype , getdns_get_errorstr_by_id(r)); + free(qname_str); continue; } + free(qname_str); if ((r = getdns_dict_set_int(dns_msg, "/replies_tree/0/header/id", qid))) { fprintf( stderr, "Could not set message ID on reply dict: \"%s\"\n" , getdns_get_errorstr_by_id(r)); diff --git a/src/test/getdns_query.c b/src/test/getdns_query.c index fb9df6f9..ba0e8c47 100644 --- a/src/test/getdns_query.c +++ b/src/test/getdns_query.c @@ -621,7 +621,7 @@ error: getdns_list_destroy(trust_anchor); getdns_list_destroy(to_validate); - return GETDNS_RETURN_GOOD; + return r; } void callback(getdns_context *context, getdns_callback_type_t callback_type, diff --git a/src/test/testmessages.c b/src/test/testmessages.c index 17e03c70..9ad430e8 100644 --- a/src/test/testmessages.c +++ b/src/test/testmessages.c @@ -45,7 +45,6 @@ tstmsg_prog_begin(char *prognm) { if (testprog != NULL) { tstmsg_prog_end(); - free(testprog); } testprog = strdup(prognm); printf("TESTPROG %s START\n", testprog); diff --git a/src/test/tests_list.c b/src/test/tests_list.c index 26df78f9..c8a68bd8 100644 --- a/src/test/tests_list.c +++ b/src/test/tests_list.c @@ -56,7 +56,7 @@ tst_bindatasetget(void) size_t index = 0; getdns_return_t retval; struct getdns_list *list = NULL; - struct getdns_bindata *new_bindata = NULL; + struct getdns_bindata new_bindata = { 0, NULL }; struct getdns_bindata *ans_bindata = NULL; tstmsg_case_begin("tst_bindatasetget"); @@ -101,12 +101,10 @@ tst_bindatasetget(void) /* test set and get legitimate use case */ - new_bindata = - (struct getdns_bindata *) malloc(sizeof(struct getdns_bindata)); - new_bindata->size = strlen("foobar") + 1; - new_bindata->data = (uint8_t *) "foobar"; + new_bindata.size = strlen("foobar") + 1; + new_bindata.data = (uint8_t *) "foobar"; - getdns_list_set_bindata(list, index, new_bindata); + getdns_list_set_bindata(list, index, &new_bindata); retval = getdns_list_get_bindata(list, index, &ans_bindata); snprintf(msg, sizeof(msg), "getdns_list_set/get_bindata,retval = %d, bindata->data = %d,%s", @@ -378,7 +376,7 @@ tst_create(void) tstmsg_case_msg("getdns_list_get_length(list)"); retval = getdns_list_get_length(list, &index); - snprintf(msg, sizeof(msg), "list length = %d", (int) index); + snprintf(msg, sizeof(msg), "list length = %d, retval = %d", (int) index, retval); tstmsg_case_msg(msg); tstmsg_case_msg("getdns_list_get_length()"); diff --git a/src/test/tpkg/340-event-loops-scan-build.tpkg/340-event-loops-scan-build.test b/src/test/tpkg/340-event-loops-scan-build.tpkg/340-event-loops-scan-build.test index 0ed2d6b6..c72c4061 100644 --- a/src/test/tpkg/340-event-loops-scan-build.tpkg/340-event-loops-scan-build.test +++ b/src/test/tpkg/340-event-loops-scan-build.tpkg/340-event-loops-scan-build.test @@ -4,13 +4,6 @@ # use .tpkg.var.test for in test variable passing [ -f .tpkg.var.test ] && source .tpkg.var.test -( - cd "${BUILDDIR}/build-event-loops" - make clean - scan-build -o ../scan-build-reports -v make everything -) && if grep "No bugs found" result.340-event-loops-scan-build -then - exit 0 -else - exit 1 -fi +cd "${BUILDDIR}/build-event-loops" +make clean +scan-build -o ../scan-build-reports -v --status-bugs make everything diff --git a/src/util-internal.c b/src/util-internal.c index 14912982..0fe67591 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -493,8 +493,7 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req, gldns_pkt_section section; uint8_t canonical_name_space[256], owner_name_space[256], query_name_space[256]; - const uint8_t *canonical_name = canonical_name_space, *owner_name, - *query_name; + const uint8_t *canonical_name, *owner_name, *query_name; size_t canonical_name_len = sizeof(canonical_name_space), owner_name_len = sizeof(owner_name_space), query_name_len = sizeof(query_name_space);