From: Tomas Krizek Date: Wed, 24 Mar 2021 16:44:48 +0000 (+0100) Subject: modules/dnstap/dnstap.c: replace asserts X-Git-Tag: v5.4.0~18^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72d5d7d1cff3077f91151bab25ae07c27a480c9b;p=thirdparty%2Fknot-resolver.git modules/dnstap/dnstap.c: replace asserts --- diff --git a/modules/dnstap/dnstap.c b/modules/dnstap/dnstap.c index 0ed57110c..56e101227 100644 --- a/modules/dnstap/dnstap.c +++ b/modules/dnstap/dnstap.c @@ -110,7 +110,8 @@ static void set_address(const struct sockaddr *sockaddr, /** Fill a tcp_info or return kr_error(). */ static int get_tcp_info(const struct kr_request *req, struct tcp_info *info) { - assert(req && info); + if(!kr_assume(req && info)) + return kr_error(EINVAL); if (!req->qsource.dst_addr || !req->qsource.flags.tcp) /* not TCP-based */ return -abs(ENOENT); /* First obtain the file-descriptor. */ @@ -373,28 +374,29 @@ static struct fstrm_writer* dnstap_unix_writer(const char *path) { return writer; } -/* find_string +/* find_string * create a new string from json * *var is set to pointer of new string * node must of type JSON_STRING * new string can be at most len bytes */ static int find_string(const JsonNode *node, char **val, size_t len) { - if (!node || !node->key) { + if (!node || !node->key) + return kr_error(EINVAL); + if (!kr_assume(node->tag == JSON_STRING)) return kr_error(EINVAL); - } - assert(node->tag == JSON_STRING); *val = strndup(node->string_, len); - assert(*val != NULL); + if (!kr_assume(*val != NULL)) + return kr_error(EFAULT); return kr_ok(); } /* find_bool returns bool from json */ static bool find_bool(const JsonNode *node) { - if (!node || !node->key) { + if (!node || !node->key) + return false; + if (!kr_assume(node->tag == JSON_BOOL)) return false; - } - assert(node->tag == JSON_BOOL); return node->bool_; }