Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Apr 2021 19:22:21 GMT
From:      Yuri Pankov <yuripv@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 913a9cc33ea5 - stable/12 - setclassenvironment: trim leading spaces in variable names
Message-ID:  <202104151922.13FJMLP6043623@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by yuripv:

URL: https://cgit.FreeBSD.org/src/commit/?id=913a9cc33ea55538f2c3366016f79f4b2a79e3d0

commit 913a9cc33ea55538f2c3366016f79f4b2a79e3d0
Author:     Yuri Pankov <yuripv@FreeBSD.org>
AuthorDate: 2021-04-11 22:02:12 +0000
Commit:     Yuri Pankov <yuripv@FreeBSD.org>
CommitDate: 2021-04-15 19:19:43 +0000

    setclassenvironment: trim leading spaces in variable names
    
    Trim leading spaces in variable names when the list is e.g.
    pretty-formatted in /etc/login.conf or ~/.login_conf.
    
    PR:             247947
    Reviewed by:    allanjude
    Differential Revision:  https://reviews.freebsd.org/D25649
    
    (cherry picked from commit eeaf9d562fe137e0c52b8c346742dccfc8bde015)
---
 lib/libutil/login_class.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index bd1ddff90111..4925c7a04664 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -232,12 +232,17 @@ setclassenvironment(login_cap_t *lc, const struct passwd * pwd, int paths)
 	    while (*set_env != NULL) {
 		char	*p = strchr(*set_env, '=');
 
-		if (p != NULL) {  /* Discard invalid entries */
+		if (p != NULL && p != *set_env) {  /* Discard invalid entries */
+		    const char	*ep;
 		    char	*np;
 
 		    *p++ = '\0';
+		    /* Strip leading spaces from variable name */
+		    ep = *set_env;
+		    while (*ep == ' ' || *ep == '\t')
+			ep++;
 		    if ((np = substvar(p, pwd, hlen, pch, nlen)) != NULL) {
-			setenv(*set_env, np, 1);
+			setenv(ep, np, 1);
 			free(np);
 		    }
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104151922.13FJMLP6043623>