From: Remi Gacogne Date: Wed, 8 Dec 2021 11:41:23 +0000 (+0100) Subject: dnsdist: Fix const-correctness of dnsdist_ffi_raw_value_t's value X-Git-Tag: auth-4.7.0-alpha0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F11078%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Fix const-correctness of dnsdist_ffi_raw_value_t's value This prevent an allocation and a copy since we can now directly pass a Lua string. --- diff --git a/pdns/dnsdistdist/dnsdist-lua-ffi-interface.h b/pdns/dnsdistdist/dnsdist-lua-ffi-interface.h index e371d9e1db..71faeb12f9 100644 --- a/pdns/dnsdistdist/dnsdist-lua-ffi-interface.h +++ b/pdns/dnsdistdist/dnsdist-lua-ffi-interface.h @@ -44,7 +44,7 @@ typedef struct dnsdist_ffi_tag { } dnsdist_ffi_tag_t; typedef struct dnsdist_ffi_raw_value { - char* value; + const char* value; uint16_t size; } dnsdist_ffi_raw_value_t; diff --git a/regression-tests.dnsdist/test_Spoofing.py b/regression-tests.dnsdist/test_Spoofing.py index cc86e6bff3..9a3e10d2d4 100644 --- a/regression-tests.dnsdist/test_Spoofing.py +++ b/regression-tests.dnsdist/test_Spoofing.py @@ -773,12 +773,10 @@ class TestSpoofingLuaFFISpoofMulti(DNSDistTest): local str = "\\192\\000\\002\\001" records[0].size = #str - records[0].value = ffi.new("char[?]", #str) - ffi.copy(records[0].value, str, #str) + records[0].value = str local str = "\\192\\000\\002\\255" - records[1].value = ffi.new("char[?]", #str) - ffi.copy(records[1].value, str, #str) + records[1].value = str records[1].size = #str ffi.C.dnsdist_ffi_dnsquestion_spoof_raw(dq, records, 2) @@ -788,13 +786,11 @@ class TestSpoofingLuaFFISpoofMulti(DNSDistTest): local str = "\\033this text has a comma at the end," records[0].size = #str - records[0].value = ffi.new("char[?]", #str) - ffi.copy(records[0].value, str, #str) + records[0].value = str local str = "\\003aaa\\004bbbb" records[1].size = #str - records[1].value = ffi.new("char[?]", #str) - ffi.copy(records[1].value, str, #str) + records[1].value = str ffi.C.dnsdist_ffi_dnsquestion_spoof_raw(dq, records, 2) return DNSAction.HeaderModify