aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Pankov <yuripv@FreeBSD.org>2021-04-11 22:02:12 +0000
committerYuri Pankov <yuripv@FreeBSD.org>2021-04-11 22:05:10 +0000
commiteeaf9d562fe137e0c52b8c346742dccfc8bde015 (patch)
tree90eabec375f4beac9556b270b50229bf648991b6
parent68b7d9b56bf38881d41f0fd00a7f7ced7844891e (diff)
downloadsrc-eeaf9d562fe137e0c52b8c346742dccfc8bde015.tar.gz
src-eeaf9d562fe137e0c52b8c346742dccfc8bde015.zip
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
-rw-r--r--lib/libutil/login_class.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index fd0b232d0a43..38666bc8e3d3 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -231,12 +231,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);
}
}