]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEV: sslkeylogger: handle file opening error
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 3 Oct 2023 13:05:56 +0000 (15:05 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 3 Oct 2023 13:23:35 +0000 (15:23 +0200)
Prevent a Lua error if output file cannot be opened when logging SSL
keys. Report a warning instead with the error description.

dev/sslkeylogger/sslkeylogger.lua

index 432fe65289c744905b07d0df4a41a1dca40e04e0..e67bf77da81a14ea10fc0f2577819e6bd405b1c4 100644 (file)
@@ -28,14 +28,18 @@ local function sslkeylog(txn, filename)
 
        -- ensure that a key is written only once by using a session variable
        if not txn:get_var('sess.sslkeylogdone') then
-               file = io.open(filename, 'a')
-               for fieldname, fetch in pairs(fields) do
-                       if fetch() then
-                               file:write(string.format('%s %s %s\n', fieldname, client_random, fetch()))
+               local file, err = io.open(filename, 'a')
+               if file then
+                       for fieldname, fetch in pairs(fields) do
+                               if fetch() then
+                                       file:write(string.format('%s %s %s\n', fieldname, client_random, fetch()))
+                               end
                        end
+                       file:close()
+               else
+                       core.Warning("Cannot open SSL log file: " .. err .. ".")
                end
 
-               file:close()
                txn:set_var('sess.sslkeylogdone', true)
        end
 end