mirror of
https://github.com/shadow-maint/shadow.git
synced 2026-01-26 14:03:17 +00:00
lib/port.c: getportent(): Make sure there are at least 2 ':' in the line
Otherwise, the line is invalidly formatted, and we ignore it.
For fixing cherry-pick conflicts, this also includes (minimal) changes
from:
- 59e5eef38f89 ("contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern")
<https://github.com/shadow-maint/shadow/pull/1035>
Closes: <https://github.com/shadow-maint/shadow/issues/1036>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Cherry-picked-from: c3f97e251ef1 ("lib/port.c: getportent(): Make sure there are at least 2 ':' in the line")
Link: <https://github.com/shadow-maint/shadow/pull/1037>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
parent
146bd13ee8
commit
b0b04dd109
21
lib/port.c
21
lib/port.c
@ -144,23 +144,19 @@ next:
|
||||
* TTY devices.
|
||||
*/
|
||||
|
||||
if (strchr(buf, ':') == NULL)
|
||||
goto next;
|
||||
|
||||
port.pt_names = ttys;
|
||||
for (cp = buf, j = 0; j < PORT_TTY; j++) {
|
||||
port.pt_names[j] = cp;
|
||||
cp = strpbrk(cp, ":,");
|
||||
if (cp == NULL)
|
||||
goto next; /* line format error */
|
||||
|
||||
if (':' == *cp) { /* end of tty name list */
|
||||
if (':' == *cp) /* end of tty name list */
|
||||
break;
|
||||
}
|
||||
|
||||
if (',' == *cp) { /* end of current tty name */
|
||||
*cp++ = '\0';
|
||||
}
|
||||
if (',' == *cp) /* end of current tty name */
|
||||
stpcpy(cp++, "");
|
||||
}
|
||||
*cp = '\0';
|
||||
cp++;
|
||||
stpcpy(cp++, "");
|
||||
port.pt_names[j] = NULL;
|
||||
|
||||
/*
|
||||
@ -170,6 +166,9 @@ next:
|
||||
* The last entry in the list is a NULL pointer.
|
||||
*/
|
||||
|
||||
if (strchr(cp, ':') == NULL)
|
||||
goto next;
|
||||
|
||||
if (':' != *cp) {
|
||||
port.pt_users = users;
|
||||
port.pt_users[0] = cp;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user