aboutsummaryrefslogtreecommitdiff
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
commitc2fafe1be0fb72aa1bd521efe2f524074bf143c7 (patch)
tree0790beda071109b1c0ef9397d442ff641f7077c9
parent6834e0dd1dcae917caa464d1fe124c2f6c6116f4 (diff)
downloadpam-c2fafe1be0fb72aa1bd521efe2f524074bf143c7.tar.gz
pam-c2fafe1be0fb72aa1bd521efe2f524074bf143c7.tar.bz2
pam-c2fafe1be0fb72aa1bd521efe2f524074bf143c7.zip
treewide: replace malloc followed by strcpy with strdup
Suggested-by: Benny Baumann <BenBE@geshi.org> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
-rw-r--r--libpam/pam_misc.c8
-rw-r--r--libpamc/pamc_load.c9
-rw-r--r--modules/pam_listfile/pam_listfile.c3
-rw-r--r--modules/pam_namespace/pam_namespace.c3
4 files changed, 6 insertions, 17 deletions
diff --git a/libpam/pam_misc.c b/libpam/pam_misc.c
index a843ebc7..721b36f3 100644
--- a/libpam/pam_misc.c
+++ b/libpam/pam_misc.c
@@ -116,14 +116,8 @@ char *_pam_strdup(const char *x)
register char *new=NULL;
if (x != NULL) {
- register size_t len;
-
- len = strlen (x) + 1; /* length of string including NUL */
- if ((new = malloc(len)) == NULL) {
- len = 0;
+ if ((new = strdup(x)) == NULL) {
pam_syslog(NULL, LOG_CRIT, "_pam_strdup: failed to get memory");
- } else {
- strcpy (new, x);
}
x = NULL;
}
diff --git a/libpamc/pamc_load.c b/libpamc/pamc_load.c
index cbf4b994..7efd5721 100644
--- a/libpamc/pamc_load.c
+++ b/libpamc/pamc_load.c
@@ -224,14 +224,13 @@ int pamc_disable(pamc_handle_t pch, const char *agent_id)
return PAM_BPC_FALSE;
}
- block->id = malloc(1 + strlen(agent_id));
+ block->id = strdup(agent_id);
if (block->id == NULL) {
D(("no memory for agent id"));
free(block);
return PAM_BPC_FALSE;
}
- strcpy(block->id, agent_id);
block->next = pch->blocked_agents;
pch->blocked_agents = block;
@@ -372,10 +371,8 @@ static pamc_id_node_t *__pamc_add_node(pamc_id_node_t *root, const char *id,
pamc_id_node_t *node = calloc(1, sizeof(pamc_id_node_t));
if (node) {
- node->agent_id = malloc(1+strlen(id));
- if (node->agent_id) {
- strcpy(node->agent_id, id);
- } else {
+ node->agent_id = strdup(id);
+ if (node->agent_id == NULL) {
free(node);
node = NULL;
}
diff --git a/modules/pam_listfile/pam_listfile.c b/modules/pam_listfile/pam_listfile.c
index a01b5a8a..3e6a7092 100644
--- a/modules/pam_listfile/pam_listfile.c
+++ b/modules/pam_listfile/pam_listfile.c
@@ -106,10 +106,9 @@ pam_sm_authenticate (pam_handle_t *pamh, int flags UNUSED,
}
else if(!strcmp(mybuf,"file")) {
free(ifname);
- ifname = malloc(strlen(myval)+1);
+ ifname = strdup(myval);
if (!ifname)
return PAM_BUF_ERR;
- strcpy(ifname,myval);
} else if(!strcmp(mybuf,"item"))
if(!strcmp(myval,"user"))
citem = PAM_USER;
diff --git a/modules/pam_namespace/pam_namespace.c b/modules/pam_namespace/pam_namespace.c
index 6937b6ac..d78111b3 100644
--- a/modules/pam_namespace/pam_namespace.c
+++ b/modules/pam_namespace/pam_namespace.c
@@ -1295,13 +1295,12 @@ static int check_inst_parent(char *ipath, struct instance_data *idata)
* admin explicitly instructs to ignore the instance parent
* mode by the "ignore_instance_parent_mode" argument).
*/
- inst_parent = malloc(strlen(ipath)+1);
+ inst_parent = strdup(ipath);
if (!inst_parent) {
pam_syslog(idata->pamh, LOG_CRIT, "Error allocating pathname string");
return PAM_SESSION_ERR;
}
- strcpy(inst_parent, ipath);
trailing_slash = strrchr(inst_parent, '/');
if (trailing_slash)
*trailing_slash = '\0';