From: Todd C. Miller Date: Thu, 8 Nov 2012 21:40:37 +0000 (-0500) Subject: Make expand_prompt() args const and free the prompt when we are X-Git-Tag: SUDO_1_8_7~1^2~348 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a7884d4745d3dfe98ff9c6688f1cd4a787bcbfe;p=sudo Make expand_prompt() args const and free the prompt when we are done with it. --- diff --git a/plugins/sudoers/check.c b/plugins/sudoers/check.c index cb2e35679..d7371dcbf 100644 --- a/plugins/sudoers/check.c +++ b/plugins/sudoers/check.c @@ -61,7 +61,6 @@ int check_user(int validated, int mode) { struct passwd *auth_pw; - char *prompt; int status, rval = true; debug_decl(check_user, SUDO_DEBUG_AUTH) @@ -104,6 +103,7 @@ check_user(int validated, int mode) status = timestamp_status(); if (status != TS_CURRENT || ISSET(validated, FLAG_CHECK_USER)) { + char *prompt; bool lectured; /* Bail out if we are non-interactive and a password is required */ @@ -124,6 +124,7 @@ check_user(int validated, int mode) rval = verify_user(auth_pw, prompt, validated); if (rval == true && lectured) set_lectured(); + efree(prompt); } /* Only update timestamp if user was validated. */ if (rval == true && ISSET(validated, VALIDATE_OK) && diff --git a/plugins/sudoers/prompt.c b/plugins/sudoers/prompt.c index b5f3d0e9b..f5c2fdb7f 100644 --- a/plugins/sudoers/prompt.c +++ b/plugins/sudoers/prompt.c @@ -48,11 +48,12 @@ * allocated result. Returns the same string if there are no escapes. */ char * -expand_prompt(char *old_prompt, char *user, char *host) +expand_prompt(const char *old_prompt, const char *user, const char *host) { size_t len, n; int subst; - char *p, *np, *new_prompt, *endp; + const char *p; + char *np, *new_prompt, *endp; debug_decl(expand_prompt, SUDO_DEBUG_AUTH) /* How much space do we need to malloc for the prompt? */ @@ -162,7 +163,7 @@ expand_prompt(char *old_prompt, char *user, char *host) } *np = '\0'; } else - new_prompt = old_prompt; + new_prompt = estrdup(old_prompt); debug_return_str(new_prompt); diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 1261b8af7..430e2a035 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -234,7 +234,7 @@ int find_path(char *, char **, struct stat *, char *, int); /* check.c */ int check_user(int validate, int mode); bool user_is_exempt(void); -char *expand_prompt(char *old_prompt, char *user, char *host); +char *expand_prompt(const char *old_prompt, const char *user, const char *host); /* timestamp.c */ void remove_timestamp(bool);