aboutsummaryrefslogtreecommitdiff
path: root/modules/pam_issue
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2023-12-15 10:14:11 +0100
committerDmitry V. Levin <ldv@strace.io>2023-12-19 12:22:59 +0000
commit2e375aad04d047e12468f93300ad7e42a8a03ff3 (patch)
tree29f31fa0bf4700476eccd4a307ef6638d9707851 /modules/pam_issue
parentc2fafe1be0fb72aa1bd521efe2f524074bf143c7 (diff)
downloadpam-2e375aad04d047e12468f93300ad7e42a8a03ff3.tar.gz
pam-2e375aad04d047e12468f93300ad7e42a8a03ff3.tar.bz2
pam-2e375aad04d047e12468f93300ad7e42a8a03ff3.zip
treewide: use asprintf to construct strings
The asprintf function is considered as given for current code already. Use it instead of calling malloc + strcpy + strcat manually. Reported-by: Benny Baumann <BenBE@geshi.org> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'modules/pam_issue')
-rw-r--r--modules/pam_issue/pam_issue.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/modules/pam_issue/pam_issue.c b/modules/pam_issue/pam_issue.c
index c08f90c3..aade642e 100644
--- a/modules/pam_issue/pam_issue.c
+++ b/modules/pam_issue/pam_issue.c
@@ -240,7 +240,6 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags UNUSED,
const char *issue_file = NULL;
int parse_esc = 1;
const void *item = NULL;
- const char *cur_prompt;
char *issue_prompt = NULL;
/* If we've already set the prompt, don't set it again */
@@ -277,10 +276,6 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags UNUSED,
return retval;
}
- cur_prompt = item;
- if (cur_prompt == NULL)
- cur_prompt = "";
-
if (parse_esc)
retval = read_issue_quoted(pamh, fp, &issue_prompt);
else
@@ -291,11 +286,10 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags UNUSED,
if (retval != PAM_SUCCESS)
goto out;
- {
- size_t size = strlen(issue_prompt) + strlen(cur_prompt) + 1;
- char *new_prompt = realloc(issue_prompt, size);
-
- if (new_prompt == NULL) {
+ if (item != NULL) {
+ const char *cur_prompt = item;
+ char *new_prompt;
+ if (asprintf(&new_prompt, "%s%s", issue_prompt, cur_prompt) < 0) {
pam_syslog(pamh, LOG_CRIT, "out of memory");
retval = PAM_BUF_ERR;
goto out;
@@ -303,7 +297,6 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags UNUSED,
issue_prompt = new_prompt;
}
- strcat(issue_prompt, cur_prompt);
retval = pam_set_item(pamh, PAM_USER_PROMPT,
(const void *) issue_prompt);
out: