git: 30e3fd1811e3 - main - nuageinit: Split pw line on :s
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 19 Nov 2026 13:57:59 UTC
The branch main has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=30e3fd1811e36ed9dc27db4bdd439a45c3725598
commit 30e3fd1811e36ed9dc27db4bdd439a45c3725598
Author: Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2026-11-13 16:39:05 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
CommitDate: 2026-11-19 13:57:28 +0000
nuageinit: Split pw line on :s
Previously we parsed a v7 pw string using "%a+:" in the match pattern,
which matches a string of letters preceeding a colon. This would fail
for userids ending in a digit or _. Instead, match runs of non-colons
using "[^:]*".
While here, correct failure string in an existing test. adduser("plop")
should fail because adduser requires a table, not a string. Report this
as the failure reason, rather than claiming that the faulre was due to
an empty value.
Reported by: llm-postcr
Reviewed by: bapt, dtxdf
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61513
---
libexec/nuageinit/nuage.lua | 2 +-
libexec/nuageinit/tests/adduser.lua | 12 +++++++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua
index 8310c4751ece..5dc8c5d30110 100644
--- a/libexec/nuageinit/nuage.lua
+++ b/libexec/nuageinit/nuage.lua
@@ -326,7 +326,7 @@ local function adduser(pwd)
local pwdstr = f:read("*a")
f:close()
if pwdstr:len() ~= 0 then
- return pwdstr:match("%a+:.+:%d+:%d+:.*:(.*):.*")
+ return pwdstr:match("[^:]*:[^:]*:%d+:%d+:[^:]*:([^:]*):")
end
if not pwd.gecos then
pwd.gecos = pwd.name .. " User"
diff --git a/libexec/nuageinit/tests/adduser.lua b/libexec/nuageinit/tests/adduser.lua
index cef6be0c0e0c..63c5f14bc555 100644
--- a/libexec/nuageinit/tests/adduser.lua
+++ b/libexec/nuageinit/tests/adduser.lua
@@ -6,7 +6,7 @@ if n.adduser() then
n.err("adduser should not accept empty value")
end
if n.adduser("plop") then
- n.err("adduser should not accept empty value")
+ n.err("adduser accepted a string (not table)")
end
local pw = {}
pw.name = "impossible_username"
@@ -14,3 +14,13 @@ local res = n.adduser(pw)
if not res then
n.err("valid adduser should return a path")
end
+
+pw = {}
+pw.name = "underscore_"
+-- Call adduser twice to test both addding and looking up an existing user.
+for i = 1, 2 do
+ local res = n.adduser(pw)
+ if not res then
+ n.err("no path returned for username ending with _")
+ end
+end