Skip to content

Commit 46cb271

Browse files
committed
Refactor: tools: Strip trailing whitespace in load_env_vars()
We consider the value invalid if anything besides whitespace or a comment (beginning with '#') follows it on the line. Further, we ignore all trailing whitespace after a valid value. So it's fine to strip all trailing whitespace, including a newline if present, before processing. Clearly we must now look for '\0' where we previously looked for '\n'. Signed-off-by: Reid Wahl <[email protected]>
1 parent b5107df commit 46cb271

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

daemons/execd/remoted_pidone.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ load_env_vars(void)
112112
char *value_end = NULL;
113113
char *quote = NULL;
114114

115-
// Strip leading whitespace
116-
g_strchug(line);
115+
// Strip leading and trailing whitespace
116+
g_strstrip(line);
117117

118118
// Look for valid name immediately followed by equals sign
119119
if (!find_env_var_name(line, &name, &end) || (*++end != '=')) {
@@ -157,15 +157,17 @@ load_env_vars(void)
157157

158158
/* We have a valid name and value, and end is now the character after
159159
* the closing quote or the first whitespace after the unquoted value.
160-
* Make sure the rest of the line is just whitespace or a comment.
160+
* Make sure the rest of the line, if any, is just optional whitespace
161+
* followed by a comment.
161162
*/
162163
value_end = end;
163164

164-
while (isspace(*end) && (*end != '\n')) {
165+
while (isspace(*end)) {
165166
end++;
166167
}
167168

168-
if ((*end != '\n') && (*end != '#')) {
169+
if ((*end != '\0') && (*end != '#')) {
170+
// Found garbage after value
169171
goto cleanup_loop;
170172
}
171173

0 commit comments

Comments
 (0)