From 4b775cbff9a8dc1b34a630dec493161e7a4cc716 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 2 Sep 2023 14:15:43 +0200 Subject: [PATCH] lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning I used size_t because: sysconf(3) can return -1 if the value is not supported, but then it can only mean that there's no limit. Having no limit is the same as having a limit of SIZE_MAX (to which -1 is converted). Signed-off-by: Alejandro Colomar Cherry-picked-from: 6be85b0bafb5 ("lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning") [alx: This is to cherry-pick the next commit without conflict] Link: Link: Cc: Serge Hallyn Cc: Tobias Stoeckmann Signed-off-by: Alejandro Colomar --- lib/chkname.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/chkname.c b/lib/chkname.c index 2b83361b..d22e1b6b 100644 --- a/lib/chkname.c +++ b/lib/chkname.c @@ -74,12 +74,14 @@ static bool is_valid_name (const char *name) bool is_valid_user_name (const char *name) { + size_t maxlen; + /* * User names length are limited by the kernel */ - if (strlen (name) > sysconf(_SC_LOGIN_NAME_MAX)) { + maxlen = sysconf(_SC_LOGIN_NAME_MAX); + if (strlen(name) > maxlen) return false; - } return is_valid_name (name); }