Index | Thread | Search

From:
Piotr Durlej <pdurlej@cat4u.org>
Subject:
su: produce a meaningful diagnostic in case of an empty login name
To:
tech@openbsd.org
Date:
Fri, 17 Jul 2026 18:27:19 +0200

Download raw body.

Thread
  • Piotr Durlej:

    su: produce a meaningful diagnostic in case of an empty login name

Hello,

su(1) doesn't seem to check for empty login names and an improper diagnostic
is printed in case of a zero-length name:

$ su ''
su: Invalid argument
$

Here's a patch:

---
 usr.bin/su/su.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c
index 1ff9d7f036d..5fa6cbc484b 100644
--- a/usr.bin/su/su.c
+++ b/usr.bin/su/su.c
@@ -195,6 +195,9 @@ main(int argc, char **argv)
 			style = p;	/* XXX overrides -a flag */
 		}
 
+		if (!*user)
+			errx(1, "empty login name");
+
 		/*
 		 * Clean and setup our current authentication session.
 		 * Note that options *are* not cleared.
-- 
2.53.0