]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/dnstap/dnstap.c: replace asserts
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 24 Mar 2021 16:44:48 +0000 (17:44 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 25 May 2021 12:39:43 +0000 (14:39 +0200)
modules/dnstap/dnstap.c

index 0ed57110c31a9c782a285cb47203cb408ed0d057..56e101227e1f11e2b8c457342b8e535757d595ef 100644 (file)
@@ -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_;
 }