Skip to content

Conversation

@ikerexxe
Copy link
Collaborator

The chgpasswd command was incorrectly reporting "missing new password" when processing files with a trailing newline. This happened because the code was missing an EOF check.

Reproduction steps:
$ groupadd tgroup1
$ groupadd tgroup2
$ cat /tmp/test_chgpasswd.txt
tgroup1:Secret123
tgroup2:Secret456

$ #The file contains a trailing newline
$ chgpasswd < /tmp/test_chgpasswd.txt
chgpasswd: line 3: missing new password
chgpasswd: error detected, changes ignored

The chgpasswd command was incorrectly reporting "missing new password"
when processing files with a trailing newline. This happened because the
code was missing an EOF check.

Reproduction steps:
$ groupadd tgroup1
$ groupadd tgroup2
$ cat /tmp/test_chgpasswd.txt
tgroup1:Secret123
tgroup2:Secret456

$ #The file contains a trailing newline
$ chgpasswd < /tmp/test_chgpasswd.txt
chgpasswd: line 3: missing new password
chgpasswd: error detected, changes ignored

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
@alejandro-colomar
Copy link
Collaborator

From that reproducer, what I observe is a spurious empty line, not a file without trailing newline.

That is, the file ends with 2 new-line characters instead of just 1.

@alejandro-colomar
Copy link
Collaborator

From that reproducer, what I observe is a spurious empty line, not a file without trailing newline.

That is, the file ends with 2 new-line characters instead of just 1.

The proposed patch shouldn't change the behavior of the reproducer you shared, I think.

Instead, we should either:

  • continue rejecting blank lines.
  • add code to accept and ignore blank lines.

Comment on lines 481 to 488
if (stpsep(buf, "\n") == NULL) {
fprintf (stderr, _("%s: line %jd: line too long\n"),
Prog, line);
errors = true;
continue;
if (feof(stdin) == 0) {
fprintf (stderr, _("%s: line %jd: line too long\n"),
Prog, line);
errors = true;
continue;
}
}
Copy link
Collaborator

@alejandro-colomar alejandro-colomar Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this code runs only when a newline is not found, it won't change the behavior in the shown reproducer, which has the opposite problem: too many newlines are present.

@alejandro-colomar
Copy link
Collaborator

The chgpasswd command was incorrectly reporting "missing new password" when processing files with a trailing newline. This happened because the code was missing an EOF check.

Reproduction steps: $ groupadd tgroup1 $ groupadd tgroup2 $ cat /tmp/test_chgpasswd.txt tgroup1:Secret123 tgroup2:Secret456

$ #The file contains a trailing newline $ chgpasswd < /tmp/test_chgpasswd.txt chgpasswd: line 3: missing new password chgpasswd: error detected, changes ignored

Do you have a use case for files with blank lines?

@ikerexxe
Copy link
Collaborator Author

It turns out that I was creating the file incorrectly 🤦

@ikerexxe ikerexxe closed this Dec 30, 2025
@ikerexxe ikerexxe deleted the chgpasswd-eof branch December 30, 2025 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants