]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dns: dns-lua - Return error correctly
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 3 Oct 2022 15:45:36 +0000 (18:45 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 4 Oct 2022 09:15:26 +0000 (12:15 +0300)
Code was checking wrong place in stack, and thus only returned top of stack.
Check the right place for error.

Broken in a4e3ea5089400ab2037d3bdd0daa0ed351c1be46

src/lib-dns/dns-lua.c
src/lib-lua/test-dns-lua.c

index 0ed7c43494eed19fc63f61792b6ef5fcc15506f3..946cca94475581b177a078511f38c538b3e7c2de 100644 (file)
@@ -31,7 +31,7 @@ static int
 lua_dns_client_async_continue(lua_State *L, int status ATTR_UNUSED,
                              lua_KContext ctx ATTR_UNUSED)
 {
-       if (lua_isnil(L, -1))
+       if (lua_isnil(L, -3))
                return 3;
        else
                return 1;
@@ -56,7 +56,7 @@ lua_dns_client_lookup_callback(const struct dns_lookup_result *result,
        }
 
        if (lua_lookup->resume)
-               dlua_pcall_yieldable_resume(L, 1);
+               dlua_pcall_yieldable_resume(L, result->ret == 0 ? 1 : 3);
        i_free(lua_lookup);
 }
 
index fd43dd036cef8772e141acd151b2107a8aa2e100..3aa4b5de033e3056b5eaa596219e562285cdc028 100644 (file)
@@ -141,6 +141,10 @@ static void test_dns_lua(void)
 "  assert(#arr == 2)\n"
 "  assert(arr[1] == '127.0.0.1')\n"
 "  assert(arr[2] == '127.0.0.2')\n"
+"  local arr, error, errno = client:lookup('invalid..name')\n"
+"  assert(arr == nil)\n"
+"  assert(errno == -4)\n"
+"  assert(error == \"Unknown host\")\n"
 "end\n";
        test_begin("dns lua lookup");