nuageinit: Add guards against empty user data

Add guards against attempting to process a user data file with an empty
first line or contents.

PR:		290395
Reviewed by:	bapt (earlier), dtxdf, markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D53239
This commit is contained in:
Jose Luis Duran
2025-10-21 13:11:50 +00:00
parent 81af04b081
commit 57d25b6333
+8
View File
@@ -663,8 +663,16 @@ if not f then
os.exit(0)
end
local line = f:read("*l")
if not line or #string.gsub(line, "^%s*(.-)%s*$", "%1") == 0 then
f:close()
os.exit(0)
end
if citype ~= "postnet" then
local content = f:read("*a")
if not content or #string.gsub(content, "^%s*(.-)%s*$", "%1") == 0 then
f:close()
os.exit(0)
end
nuage.mkdir_p(root .. "/var/cache/nuageinit")
local tof = assert(io.open(root .. "/var/cache/nuageinit/user_data", "w"))
tof:write(line .. "\n" .. content)