git: ea0932d71aa7 - main - nuageinit: refactor goto abuse in chpasswd()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 04 Jun 2026 21:15:48 UTC
The branch main has been updated by bapt:
URL: https://cgit.FreeBSD.org/src/commit/?id=ea0932d71aa7a2d25b178f1593bfad194d8c7929
commit ea0932d71aa7a2d25b178f1593bfad194d8c7929
Author: Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2026-06-04 20:02:58 +0000
Commit: Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2026-06-04 20:02:58 +0000
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 bdd4bf60007e..e2db27bc7e85 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
- 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
+ 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
- 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