aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2024-01-02 22:10:19 +0100
committerDmitry V. Levin <ldv@strace.io>2024-01-03 17:28:06 +0000
commite63896102fb7a0431d5590b07e9fc24ffc6813c1 (patch)
tree2b400e374405a5c492091767ca237f634f29535e
parent5a0b61224f538d832d4f88b169524c138648b0c2 (diff)
downloadpam-e63896102fb7a0431d5590b07e9fc24ffc6813c1.tar.gz
pam-e63896102fb7a0431d5590b07e9fc24ffc6813c1.tar.bz2
pam-e63896102fb7a0431d5590b07e9fc24ffc6813c1.zip
pam_securetty: use getline
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
-rw-r--r--modules/pam_securetty/pam_securetty.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/modules/pam_securetty/pam_securetty.c b/modules/pam_securetty/pam_securetty.c
index e51b0062..f60cf32a 100644
--- a/modules/pam_securetty/pam_securetty.c
+++ b/modules/pam_securetty/pam_securetty.c
@@ -70,7 +70,8 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl,
const char *uttyname;
const char *str;
const void *void_uttyname;
- char ttyfileline[256];
+ char *ttyfileline = NULL;
+ size_t ttyfilelinelen = 0;
char ptname[256];
struct stat ttyfileinfo;
struct passwd *user_pwd;
@@ -156,7 +157,7 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl,
retval = 1;
- while ((fgets(ttyfileline, sizeof(ttyfileline)-1, ttyfile) != NULL)
+ while ((getline(&ttyfileline, &ttyfilelinelen, ttyfile) != -1)
&& retval) {
size_t len;
len = strlen(ttyfileline);
@@ -166,6 +167,7 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl,
retval = ( strcmp(ttyfileline, uttyname)
&& (!ptname[0] || strcmp(ptname, uttyname)) );
}
+ free(ttyfileline);
fclose(ttyfile);
if (retval && !(ctrl & PAM_NOCONSOLE_ARG)) {
@@ -175,9 +177,14 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl,
cmdlinefile = fopen(CMDLINE_FILE, "r");
if (cmdlinefile != NULL) {
- char line[LINE_MAX], *p;
-
- p = fgets(line, sizeof(line), cmdlinefile);
+ char *p;
+ char *line = NULL;
+ size_t linelen = 0;
+
+ if (getline(&line, &linelen, cmdlinefile) == -1)
+ p = NULL;
+ else
+ p = line;
fclose(cmdlinefile);
for (; p; p = strstr(p+1, "console=")) {
@@ -197,6 +204,8 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl,
break;
}
}
+
+ free(line);
}
}
if (retval && !(ctrl & PAM_NOCONSOLE_ARG)) {
@@ -206,10 +215,14 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl,
consoleactivefile = fopen(CONSOLEACTIVE_FILE, "r");
if (consoleactivefile != NULL) {
- char line[LINE_MAX], *p, *n;
-
- line[0] = 0;
- p = fgets(line, sizeof(line), consoleactivefile);
+ char *p, *n;
+ char *line = NULL;
+ size_t linelen = 0;
+
+ if (getline(&line, &linelen, consoleactivefile) == -1)
+ p = NULL;
+ else
+ p = line;
fclose(consoleactivefile);
if (p) {
@@ -230,6 +243,8 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl,
}
}
}
+
+ free(line);
}
}