Skip to content

Conversation

@ikerexxe
Copy link
Collaborator

Fix chgpasswd to properly handle input files that don't end with a newline, similar to how chpasswd handles this case. Previously, chgpasswd would incorrectly report "line too long" errors when processing the last line of a file that didn't end with a newline character.

The fix adds proper end-of-file detection and long line handling logic consistent with chpasswd implementation.

I discovered this issue while developing test_chgpasswd__change_passwords_from_file from #1357.

Fix chgpasswd to properly handle input files that don't end with a
newline, similar to how chpasswd handles this case. Previously,
chgpasswd would incorrectly report "line too long" errors when
processing the last line of a file that didn't end with a newline
character.

The fix adds proper end-of-file detection and long line handling logic
consistent with chpasswd implementation.

Signed-off-by: Iker Pedrosa <[email protected]>
* file (gshadow or group) and the password changed.
*/
while (fgets (buf, (int) sizeof buf, stdin) != NULL) {
char *cp;

Check notice

Code scanning / CodeQL

Declaration hides variable Note

Variable cp hides another variable of the same name (on
line 420
).
@alejandro-colomar
Copy link
Collaborator

alejandro-colomar commented Sep 12, 2025

Fix chgpasswd to properly handle input files that don't end with a newline, similar to how chpasswd handles this case. Previously, chgpasswd would incorrectly report "line too long" errors when processing the last line of a file that didn't end with a newline character.

I don't like handling files without a trailing newline. Those files are not POSIX conforming, and we should reject them.
https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap03.html#tag_03_387

I strongly oppose this change, as it increases the complexity of the code unnecessarily.

Instead files should be fixed to have a trailing line, which is simple to fix.

The fix adds proper end-of-file detection and long line handling logic consistent with chpasswd implementation.

I want to remove that code, actually.

I discovered this issue while developing test_chgpasswd__change_passwords_from_file from #1357.

@ikerexxe
Copy link
Collaborator Author

I don't like handling files without a trailing newline. Those files are not POSIX conforming, and we should reject them. https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap03.html#tag_03_387

I strongly oppose this change, as it increases the complexity of the code unnecessarily.

After reading this definition, I agree with you. I proceed to close the PR.

@ikerexxe ikerexxe closed this Sep 15, 2025
@alejandro-colomar
Copy link
Collaborator

I don't like handling files without a trailing newline. Those files are not POSIX conforming, and we should reject them. https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap03.html#tag_03_387
I strongly oppose this change, as it increases the complexity of the code unnecessarily.

After reading this definition, I agree with you. I proceed to close the PR.

Thanks! :-)

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