From 6ced08bfa6bc773baae5d299e6161972f9a33fef Mon Sep 17 00:00:00 2001 From: Thomas Quinot Date: Mon, 10 Feb 2003 11:20:58 +0000 Subject: [PATCH] Allow inner whitespace in the right-hand side of an environment variable assignment even if it is not quoted (as advertised by the man page). This fixes a regression wrt RELENG_4 introduced in rev. 1.11. Problem noted and patch tested by: CHOI Junho Reviewed by: roberto --- usr.sbin/cron/lib/env.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/usr.sbin/cron/lib/env.c b/usr.sbin/cron/lib/env.c index c2adb49bb2d..fd358176b12 100644 --- a/usr.sbin/cron/lib/env.c +++ b/usr.sbin/cron/lib/env.c @@ -193,14 +193,16 @@ load_env(envstr, f) break; } } else { - if (isspace (*c)) { - state++; - c++; - break; - } - if (state == NAME && *c == '=') { - state++; - break; + if (state == NAME) { + if (isspace (*c)) { + c++; + state++; + break; + } + if (*c == '=') { + state++; + break; + } } } *str++ = *c++; @@ -232,9 +234,14 @@ load_env(envstr, f) Set_LineNum(fileline); return (FALSE); } + if (state == VALUE) { + /* End of unquoted value: trim trailing whitespace */ + c = val + strlen (val); + while (c > val && isspace (*(c - 1))) + *(--c) = '\0'; + } - /* 2 fields from parser; looks like an env setting - */ + /* 2 fields from parser; looks like an env setting */ if (strlen(name) + 1 + strlen(val) >= MAX_ENVSTR-1) return (FALSE);