Skip to content

Commit 3a7615c

Browse files
committed
Refactor: remoted: Strip trailing comment in load_env_vars()
We don't want to do this until after parsing the value, because a '#' character inside a quoted value should be treated as part of the value. Note that currently if an unquoted value ends in '#' characters, they are treated as part of the value. I consider this a bug. For example, name=value### # comment would set the "name" environment variable to "value###". For an unquoted value, I would expect "name" to be set to "value". For a quoted value, such as name="value###" # comment I would indeed expect "name" to be set to "value###". Signed-off-by: Reid Wahl <[email protected]>
1 parent 46cb271 commit 3a7615c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

daemons/execd/remoted_pidone.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ load_env_vars(void)
111111
char *value = NULL;
112112
char *value_end = NULL;
113113
char *quote = NULL;
114+
char *comment = NULL;
114115

115116
// Strip leading and trailing whitespace
116117
g_strstrip(line);
@@ -162,11 +163,17 @@ load_env_vars(void)
162163
*/
163164
value_end = end;
164165

166+
// Strip trailing comment beginning with '#'
167+
comment = strchr(end, '#');
168+
if (comment != NULL) {
169+
*comment = '\0';
170+
}
171+
165172
while (isspace(*end)) {
166173
end++;
167174
}
168175

169-
if ((*end != '\0') && (*end != '#')) {
176+
if (*end != '\0') {
170177
// Found garbage after value
171178
goto cleanup_loop;
172179
}

0 commit comments

Comments
 (0)