From ea0932d71aa7a2d25b178f1593bfad194d8c7929 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Thu, 4 Jun 2026 22:02:58 +0200 Subject: [PATCH] nuageinit: refactor goto abuse in chpasswd() Replace goto next/list pattern with proper elseif/else control structure. The goto-based flow was fragile and hard to follow; the elseif chain makes the validation logic explicit and linear. --- libexec/nuageinit/nuage.lua | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua index bdd4bf60007..e2db27bc7e8 100644 --- a/libexec/nuageinit/nuage.lua +++ b/libexec/nuageinit/nuage.lua @@ -605,26 +605,20 @@ local function chpasswd(obj) if obj.users ~= nil then if type(obj.users) ~= "table" then warnmsg("Invalid type for chpasswd.users, expecting a list, got a ".. type(obj.users)) - goto list - end - for _, u in ipairs(obj.users) do - if type(u) ~= "table" then - warnmsg("Invalid chpasswd.users entry, expecting an object, got a " .. type(u)) - goto next + else + for _, u in ipairs(obj.users) do + if type(u) ~= "table" then + warnmsg("Invalid chpasswd.users entry, expecting an object, got a " .. type(u)) + elseif not u.name then + warnmsg("Invalid entry for chpasswd.users: missing 'name'") + elseif not u.password then + warnmsg("Invalid entry for chpasswd.users: missing 'password'") + else + exec_change_password(u.name, u.password, u.type, expire) + end end - if not u.name then - warnmsg("Invalid entry for chpasswd.users: missing 'name'") - goto next - end - if not u.password then - warnmsg("Invalid entry for chpasswd.users: missing 'password'") - goto next - end - exec_change_password(u.name, u.password, u.type, expire) - ::next:: end end - ::list:: if obj.list ~= nil then warnmsg("chpasswd.list is deprecated consider using chpasswd.users") if type(obj.list) == "string" then