Skip to content

Commit

Permalink
Fix minor leak in clean_environ()
Browse files Browse the repository at this point in the history
my_strpos() modifies the string pointer causing us to free
an incorrect pointer.
  • Loading branch information
dougnazar committed May 1, 2023
1 parent 3ba5ff3 commit 03c04a2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ int clean_environ(const char *keep_env_vars, const char *nrpe_user)
#endif
struct passwd *pw = NULL;
size_t len, var_sz = 0;
char **kept = NULL, *value, *var, *keep = NULL;
char **kept = NULL, *value, *var, *keep = NULL, *tmp;
int i, j, keepcnt = 0;

if (keep_env_vars && *keep_env_vars)
Expand All @@ -289,7 +289,8 @@ int clean_environ(const char *keep_env_vars, const char *nrpe_user)
logit(LOG_ERR, "Could not sanitize the environment. Aborting!");
return ERROR;
}
for (i = 0, var = my_strsep(&keep, ","); var != NULL; var = my_strsep(&keep, ","))
tmp = keep; /* use temp variable as strsep will update it */
for (i = 0, var = my_strsep(&tmp, ","); var != NULL; var = my_strsep(&tmp, ","))
kept[i++] = strip(var);

var = NULL;
Expand Down

0 comments on commit 03c04a2

Please sign in to comment.