From 4fdf3a8b2a30091900e622359f0627d26d0d58a4 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Fri, 20 Dec 2019 11:09:24 +0000 Subject: [PATCH] Stuff that came out of valgrind on FreeBSD 12 --- src/anchor.c | 2 +- src/context.c | 2 +- src/convert.c | 2 +- src/dict.c | 2 +- src/gldns/str2wire.c | 2 +- ...rind-checks.parse_valgrind_suppressions.sh | 57 ++++++++++ .../125-valgrind-checks.supp | 62 +++++++++++ .../125-valgrind-checks.test | 9 ++ ...rind-checks.parse_valgrind_suppressions.sh | 57 ++++++++++ .../225-stub-only-valgrind-checks.queries | 7 ++ .../225-stub-only-valgrind-checks.supp | 102 ++++++++++++++++++ .../225-stub-only-valgrind-checks.test | 20 ++-- .../275-server-capabilities.c | 4 +- .../280-limit_outstanding_queries.c | 2 +- .../285-out_of_filedescriptors.c | 2 +- 15 files changed, 313 insertions(+), 19 deletions(-) create mode 100755 src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.parse_valgrind_suppressions.sh create mode 100755 src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.parse_valgrind_suppressions.sh create mode 100644 src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.queries create mode 100644 src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.supp diff --git a/src/anchor.c b/src/anchor.c index 4cab4e65..f50c4a3d 100644 --- a/src/anchor.c +++ b/src/anchor.c @@ -1228,7 +1228,7 @@ void _getdns_start_fetching_ta( { getdns_return_t r; size_t scheduled; - char tas_hostname[256]; + char tas_hostname[256] = ""; const char *verify_CA; const char *verify_email; diff --git a/src/context.c b/src/context.c index 2f190129..57686f0a 100644 --- a/src/context.c +++ b/src/context.c @@ -3486,7 +3486,7 @@ static getdns_return_t ub_setup_recursing(struct ub_ctx *ctx, getdns_context *context) { _getdns_rr_iter rr_spc, *rr; - char ta_str[8192]; + char ta_str[8192] = ""; int r; if ((r = ub_ctx_set_fwd(ctx, NULL))) { diff --git a/src/convert.c b/src/convert.c index 5cb9265b..55426da0 100644 --- a/src/convert.c +++ b/src/convert.c @@ -1356,7 +1356,7 @@ static int _jsmn_get_int(const char *js, jsmntok_t *t, uint32_t *value) static int _jsmn_get_const(const char *js, jsmntok_t *t, uint32_t *value) { - char value_str[80]; + char value_str[80] = ""; int size = t->end - t->start; if (size <= 0 || size >= (int)sizeof(value_str)) diff --git a/src/dict.c b/src/dict.c index f1ccb1a4..3a90f52c 100644 --- a/src/dict.c +++ b/src/dict.c @@ -83,7 +83,7 @@ static char *_json_ptr_first(const struct mem_funcs *mf, static struct getdns_dict_item * _find_dict_item(const getdns_dict *dict, const char *jptr) { - char first_spc[1024], *first; + char first_spc[1024] = "", *first; struct getdns_dict_item *d; first = _json_ptr_first(&dict->mf, jptr, diff --git a/src/gldns/str2wire.c b/src/gldns/str2wire.c index c2225621..29de56d8 100644 --- a/src/gldns/str2wire.c +++ b/src/gldns/str2wire.c @@ -737,7 +737,7 @@ gldns_str2wire_rr_buf_internal(const char* str, uint8_t* rr, size_t* len, { int status; int not_there = 0; - char token[GLDNS_MAX_RDFLEN+1]; + char token[GLDNS_MAX_RDFLEN+1] = ""; uint32_t ttl = 0; uint16_t tp = 0, cl = 0; size_t ddlen = 0; diff --git a/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.parse_valgrind_suppressions.sh b/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.parse_valgrind_suppressions.sh new file mode 100755 index 00000000..94c2be8a --- /dev/null +++ b/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.parse_valgrind_suppressions.sh @@ -0,0 +1,57 @@ +#! /usr/local/bin/gawk -f +# A script to extract the actual suppression info from the output of (for example) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all ./minimal +# The desired bits are between ^{ and ^} (including the braces themselves). +# The combined output should either be appended to /usr/lib/valgrind/default.supp, or placed in a .supp of its own +# If the latter, either tell valgrind about it each time with --suppressions=, or add that line to ~/.valgrindrc + +# NB This script uses the |& operator, which I believe is gawk-specific. In case of failure, check that you're using gawk rather than some other awk + +# The script looks for suppressions. When it finds one it stores it temporarily in an array, +# and also feeds it line by line to the external app 'md5sum' which generates a unique checksum for it. +# The checksum is used as an index in a different array. If an item with that index already exists the suppression must be a duplicate and is discarded. + +BEGIN { suppression=0; md5sum = "md5" } + # If the line begins with '{', it's the start of a supression; so set the var and initialise things + /^{/ { + suppression=1; i=0; next + } + # If the line begins with '}' its the end of a suppression + /^}/ { + if (suppression) + { suppression=0; + close(md5sum, "to") # We've finished sending data to md5sum, so close that part of the pipe + ProcessInput() # Do the slightly-complicated stuff in functions + delete supparray # We don't want subsequent suppressions to append to it! + } + } + # Otherwise, it's a normal line. If we're inside a supression, store it, and pipe it to md5sum. Otherwise it's cruft, so ignore it + { if (suppression) + { + supparray[++i] = $0 + print |& md5sum + } + } + + + function ProcessInput() + { + # Pipe the result from md5sum, then close it + md5sum |& getline result + close(md5sum) + # gawk can't cope with enormous ints like $result would be, so stringify it first by prefixing a definite string + resultstring = "prefix"result + + if (! (resultstring in chksum_array) ) + { chksum_array[resultstring] = 0; # This checksum hasn't been seen before, so add it to the array + OutputSuppression() # and output the contents of the suppression + } + } + + function OutputSuppression() + { + # A suppression is surrounded by '{' and '}'. Its data was stored line by line in the array + print "{" + for (n=1; n <= i; ++n) + { print supparray[n] } + print "}" + } diff --git a/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.supp b/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.supp index 08185a7f..6ac49f58 100644 --- a/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.supp +++ b/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.supp @@ -16,3 +16,65 @@ fun:pthread_attr_init obj:/usr/local/lib/libunbound.so.8.1.5 } +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:/lib/libc.so.7 + obj:* + obj:/lib/libc.so.7 + obj:* + obj:/lib/libc.so.7 + obj:/lib/libc.so.7 + obj:/lib/libc.so.7 + obj:/root/getdns/tests/build/getdns_query + obj:/lib/libc.so.7 +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + fun:_getdns_submit_netreq + fun:getdns_general_ns +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + fun:_getdns_submit_netreq +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 +} diff --git a/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.test b/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.test index 648f2757..d8cd7837 100644 --- a/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.test +++ b/src/test/tpkg/125-valgrind-checks.tpkg/125-valgrind-checks.test @@ -4,6 +4,15 @@ # use .tpkg.var.test for in test variable passing [ -f .tpkg.var.test ] && source .tpkg.var.test +## To add suppressions: +## +# +# valgrind -v --log-file=valgrind.log --suppressions="${TPKG_NAME}.supp" --leak-check=full --error-exitcode=1 --track-origins=yes --gen-suppressions=all "${GETDNS_QUERY}" -F "${TPKG_NAME}.queries" -f "${TPKG_NAME}.ds" +dnssec_return_validation_chain +# ./${PKG_NAME}.parse_valgrind_suppressions.sh > new_supps +# cat ${PKG_NAME}.supp new_supps > tmp_supps +# mv tmp_supps ${PKG_NAME}.supp +# + ( if ! valgrind -v --log-file=valgrind.log --suppressions="${TPKG_NAME}.supp" --leak-check=full --error-exitcode=1 --track-origins=yes "${GETDNS_QUERY}" -F "${TPKG_NAME}.queries" -f "${TPKG_NAME}.ds" +dnssec_return_validation_chain then diff --git a/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.parse_valgrind_suppressions.sh b/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.parse_valgrind_suppressions.sh new file mode 100755 index 00000000..94c2be8a --- /dev/null +++ b/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.parse_valgrind_suppressions.sh @@ -0,0 +1,57 @@ +#! /usr/local/bin/gawk -f +# A script to extract the actual suppression info from the output of (for example) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all ./minimal +# The desired bits are between ^{ and ^} (including the braces themselves). +# The combined output should either be appended to /usr/lib/valgrind/default.supp, or placed in a .supp of its own +# If the latter, either tell valgrind about it each time with --suppressions=, or add that line to ~/.valgrindrc + +# NB This script uses the |& operator, which I believe is gawk-specific. In case of failure, check that you're using gawk rather than some other awk + +# The script looks for suppressions. When it finds one it stores it temporarily in an array, +# and also feeds it line by line to the external app 'md5sum' which generates a unique checksum for it. +# The checksum is used as an index in a different array. If an item with that index already exists the suppression must be a duplicate and is discarded. + +BEGIN { suppression=0; md5sum = "md5" } + # If the line begins with '{', it's the start of a supression; so set the var and initialise things + /^{/ { + suppression=1; i=0; next + } + # If the line begins with '}' its the end of a suppression + /^}/ { + if (suppression) + { suppression=0; + close(md5sum, "to") # We've finished sending data to md5sum, so close that part of the pipe + ProcessInput() # Do the slightly-complicated stuff in functions + delete supparray # We don't want subsequent suppressions to append to it! + } + } + # Otherwise, it's a normal line. If we're inside a supression, store it, and pipe it to md5sum. Otherwise it's cruft, so ignore it + { if (suppression) + { + supparray[++i] = $0 + print |& md5sum + } + } + + + function ProcessInput() + { + # Pipe the result from md5sum, then close it + md5sum |& getline result + close(md5sum) + # gawk can't cope with enormous ints like $result would be, so stringify it first by prefixing a definite string + resultstring = "prefix"result + + if (! (resultstring in chksum_array) ) + { chksum_array[resultstring] = 0; # This checksum hasn't been seen before, so add it to the array + OutputSuppression() # and output the contents of the suppression + } + } + + function OutputSuppression() + { + # A suppression is surrounded by '{' and '}'. Its data was stored line by line in the array + print "{" + for (n=1; n <= i; ++n) + { print supparray[n] } + print "}" + } diff --git a/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.queries b/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.queries new file mode 100644 index 00000000..da6d6535 --- /dev/null +++ b/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.queries @@ -0,0 +1,7 @@ +NS . +-A getdnsapi.net +qwerlkjhasdfpuiqwyerm.1234kjhrqwersv.com +-G TXT bogus.nlnetlabs.nl +-H 8.8.8.8 +-H 2a04:b900:0:100::37 +-A _acme-challenge.getdnsapi.net diff --git a/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.supp b/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.supp new file mode 100644 index 00000000..f9654d70 --- /dev/null +++ b/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.supp @@ -0,0 +1,102 @@ + +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:/lib/libc.so.7 + obj:* + obj:/lib/libc.so.7 + obj:* + obj:/lib/libc.so.7 + obj:/lib/libc.so.7 + obj:/lib/libc.so.7 + obj:/root/getdns/tests/build-stub-only/getdns_query + obj:/lib/libc.so.7 +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + obj:/lib/libc.so.7 +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + fun:strcpytrunc + fun:ta_iter_next + fun:ta_iter_init + fun:_getdns_parse_xml_trust_anchors_buf + fun:_getdns_context_equip_with_anchor + fun:getdns_general_ns + fun:_getdns_general_loop + fun:getdns_general_sync + fun:do_the_call + fun:read_line_cb +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + fun:strcpytrunc + fun:ta_iter_next + fun:_getdns_parse_xml_trust_anchors_buf + fun:_getdns_context_equip_with_anchor + fun:getdns_general_ns + fun:_getdns_general_loop + fun:getdns_general_sync + fun:do_the_call + fun:read_line_cb + fun:poll_read_cb +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + fun:_getdns_submit_netreq + fun:getdns_general_ns +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + fun:_getdns_submit_netreq +} +{ + + Memcheck:Cond + obj:/lib/libc.so.7 + obj:* + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 + obj:/usr/local/lib/libunbound.so.8.1.5 +} diff --git a/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.test b/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.test index bd084b53..0165ac9c 100644 --- a/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.test +++ b/src/test/tpkg/225-stub-only-valgrind-checks.tpkg/225-stub-only-valgrind-checks.test @@ -4,17 +4,17 @@ # use .tpkg.var.test for in test variable passing [ -f .tpkg.var.test ] && source .tpkg.var.test -cat >queries < new_supps +# cat ${TPKG_NAME}.supp new_supps > tmp_supps +# mv tmp_supps ${TPKG_NAME}.supp +# + ( - if ! valgrind -v --log-file=valgrind.log --leak-check=full --error-exitcode=1 --track-origins=yes "${GETDNS_STUB_QUERY}" -F queries -f "${TPKG_NAME}.ds" +dnssec_return_validation_chain + if ! valgrind -v --log-file=valgrind.log --suppressions="${TPKG_NAME}.supp" --leak-check=full --error-exitcode=1 --track-origins=yes "${GETDNS_STUB_QUERY}" -F "${TPKG_NAME}.queries" +dnssec_return_validation_chain then exit 1 fi diff --git a/src/test/tpkg/275-server-capabilities.tpkg/275-server-capabilities.c b/src/test/tpkg/275-server-capabilities.tpkg/275-server-capabilities.c index 3e817834..c43e70c1 100644 --- a/src/test/tpkg/275-server-capabilities.tpkg/275-server-capabilities.c +++ b/src/test/tpkg/275-server-capabilities.tpkg/275-server-capabilities.c @@ -92,8 +92,8 @@ int main(int argc, char **argv) uint32_t port1 = 18000; uint32_t port2 = 18000; getdns_return_t r; - char listenliststr[1024]; - char listendictstr[1024]; + char listenliststr[1024] = ""; + char listendictstr[1024] = ""; if (argc != 2) { fprintf(stderr, "usage: %s \n", argv[0]); diff --git a/src/test/tpkg/280-limit_outstanding_queries.tpkg/280-limit_outstanding_queries.c b/src/test/tpkg/280-limit_outstanding_queries.tpkg/280-limit_outstanding_queries.c index 8337caf4..a445905d 100644 --- a/src/test/tpkg/280-limit_outstanding_queries.tpkg/280-limit_outstanding_queries.c +++ b/src/test/tpkg/280-limit_outstanding_queries.tpkg/280-limit_outstanding_queries.c @@ -114,7 +114,7 @@ int main(int argc, char **argv) getdns_dict *address = NULL; uint32_t port = 18000; getdns_return_t r; - char listenliststr[1024]; + char listenliststr[1024] = ""; if (argc != 2) { fprintf(stderr, "usage: %s \n", argv[0]); diff --git a/src/test/tpkg/285-out_of_filedescriptors.tpkg/285-out_of_filedescriptors.c b/src/test/tpkg/285-out_of_filedescriptors.tpkg/285-out_of_filedescriptors.c index 88ecaf20..f9f4e052 100644 --- a/src/test/tpkg/285-out_of_filedescriptors.tpkg/285-out_of_filedescriptors.c +++ b/src/test/tpkg/285-out_of_filedescriptors.tpkg/285-out_of_filedescriptors.c @@ -119,7 +119,7 @@ int main(int argc, char **argv) getdns_dict *address = NULL; uint32_t port = 18000; getdns_return_t r; - char listenliststr[1024]; + char listenliststr[1024] = ""; if (argc != 2) { fprintf(stderr, "usage: %s \n", argv[0]);