Explicitly override only newlines

Override only newlines with '\0' to avoid undesired truncation of
actual line content.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
This commit is contained in:
Samanta Navarro 2023-01-30 11:53:47 +00:00 committed by Serge Hallyn
parent 37ae232080
commit ffc480c2e9
2 changed files with 5 additions and 4 deletions

View File

@ -130,8 +130,8 @@ static struct port *getportent (void)
again:
/*
* Get the next line and remove the last character, which
* is a '\n'. Lines which begin with '#' are all ignored.
* Get the next line and remove optional trailing '\n'.
* Lines which begin with '#' are all ignored.
*/
if (fgets (buf, (int) sizeof buf, ports) == 0) {
@ -149,7 +149,7 @@ static struct port *getportent (void)
* TTY devices.
*/
buf[strlen (buf) - 1] = 0;
buf[strcspn (buf, "\n")] = 0;
port.pt_names = ttys;
for (cp = buf, j = 0; j < PORT_TTY; j++) {

View File

@ -71,7 +71,8 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
*/
while (fgets (buf, (int) sizeof (buf), fp) != NULL) {
buf[strlen (buf) - 1] = '\0';
/* Remove optional trailing '\n'. */
buf[strcspn (buf, "\n")] = '\0';
if (strcmp (buf, tty) == 0) {
(void) fclose (fp);
return true;