aboutsummaryrefslogtreecommitdiff
path: root/modules/pam_faillock/faillock.c
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_faillock/faillock.c
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_faillock/faillock.c')
-rw-r--r--modules/pam_faillock/faillock.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/modules/pam_faillock/faillock.c b/modules/pam_faillock/faillock.c
index 091f253a..1d2057e7 100644
--- a/modules/pam_faillock/faillock.c
+++ b/modules/pam_faillock/faillock.c
@@ -36,6 +36,7 @@
#include "config.h"
#include <string.h>
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
@@ -55,23 +56,20 @@ open_tally (const char *dir, const char *user, uid_t uid, int create)
{
char *path;
int flags = O_RDWR;
- int fd;
+ int fd, r;
if (dir == NULL || strstr(user, "../") != NULL)
/* just a defensive programming as the user must be a
* valid user on the system anyway
*/
return -1;
- path = malloc(strlen(dir) + strlen(user) + 2);
- if (path == NULL)
+ if (*dir && dir[strlen(dir) - 1] != '/')
+ r = asprintf(&path, "%s/%s", dir, user);
+ else
+ r = asprintf(&path, "%s%s", dir, user);
+ if (r < 0)
return -1;
- strcpy(path, dir);
- if (*dir && dir[strlen(dir) - 1] != '/') {
- strcat(path, "/");
- }
- strcat(path, user);
-
if (create) {
flags |= O_CREAT;
if (access(dir, F_OK) != 0) {