]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
krprint: escape non-printable strings in error messages
authorPetr Špaček <petr.spacek@nic.cz>
Tue, 27 Oct 2020 10:24:19 +0000 (11:24 +0100)
committerPetr Špaček <petr.spacek@nic.cz>
Mon, 2 Nov 2020 09:28:55 +0000 (10:28 +0100)
All strings should be properly escaped but some non-escaped versions
were leaking into error messages.

daemon/lua/krprint.lua

index 2bd4dd73fbac7d3ac231d97d7d389787fdf1f640..e6088018622dd417e18d60ffb964ae28d7681f63 100644 (file)
@@ -46,7 +46,12 @@ function base_class._fallback(self, val)
        elseif self.on_unrepresentable == 'error' then
                local key_path_msg
                if #self.tab_key_path > 0 then
-                       local key_path = '[' .. table.concat(self.tab_key_path, '][') .. ']'
+                       local str_key_path = {}
+                       for _, key in ipairs(self.tab_key_path) do
+                               table.insert(str_key_path,
+                                       string.format('%s %s', type(key), self:string(tostring(key))))
+                       end
+                       local key_path = '[' .. table.concat(str_key_path, '][') .. ']'
                        key_path_msg = string.format(' (found at [%s])', key_path)
                else
                        key_path_msg = ''
@@ -192,8 +197,8 @@ function base_class.table(self, tab)
                        item = item .. string.format('%s%s%s,', indent, note, valexpr)
                else
                        local errmsg = string.format('cannot print %s = %s (%s)',
-                               tostring(idx),
-                               tostring(val),
+                               self:string(tostring(idx)),
+                               self:string(tostring(val)),
                                table.concat(errors, ', '))
                        if self.on_unrepresentable == 'error' then
                                error(errmsg, 0)