aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2024-01-01 21:02:06 +0100
committerTobias Stoeckmann <tobias@stoeckmann.org>2024-01-02 18:07:37 +0100
commit889e84082c95f47d7bb128e844c0ceaf3b2896bb (patch)
treea447340265ff009b97682dcad0515964d00f2979
parentfdec452a05addc1c8f0f00449b6775fe2f383d8b (diff)
downloadpam-889e84082c95f47d7bb128e844c0ceaf3b2896bb.tar.gz
pam-889e84082c95f47d7bb128e844c0ceaf3b2896bb.tar.bz2
pam-889e84082c95f47d7bb128e844c0ceaf3b2896bb.zip
pam_env: reduce stack usage
It is not required to have a copy of the string in stack. This removes the need of another strncpy call which also makes future cleanups easier. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
-rw-r--r--modules/pam_env/pam_env.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/modules/pam_env/pam_env.c b/modules/pam_env/pam_env.c
index 74e02638..3c4569db 100644
--- a/modules/pam_env/pam_env.c
+++ b/modules/pam_env/pam_env.c
@@ -581,9 +581,9 @@ _expand_arg(pam_handle_t *pamh, char **value)
* a constant so that the compiler will shut up when I
* call pam_getenv and _pam_get_item_byname -- sigh
*/
+ const char *tmpval;
- /* No unexpanded variable can be bigger than BUF_SIZE */
- char type, tmpval[BUF_SIZE];
+ char type;
/* I know this shouldn't be hard-coded but it's so much easier this way */
char tmp[MAX_ENV] = {};
@@ -639,8 +639,7 @@ _expand_arg(pam_handle_t *pamh, char **value)
"Unterminated expandable variable: <%s>", orig-2);
goto abort_err;
}
- strncpy(tmpval, orig, sizeof(tmpval));
- tmpval[sizeof(tmpval)-1] = '\0';
+ tmpval = orig;
orig=ptr;
/*
* so, we know we need to expand tmpval, it is either
@@ -704,17 +703,14 @@ _expand_arg(pam_handle_t *pamh, char **value)
}
strcpy(*value, tmp);
pam_overwrite_array(tmp);
- pam_overwrite_array(tmpval);
D(("Exit."));
return PAM_SUCCESS;
buf_err:
pam_overwrite_array(tmp);
- pam_overwrite_array(tmpval);
return PAM_BUF_ERR;
abort_err:
pam_overwrite_array(tmp);
- pam_overwrite_array(tmpval);
return PAM_ABORT;
}