-
Notifications
You must be signed in to change notification settings - Fork 254
Make parsing of gecos field more robust and strict #1307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cf7ed0a to
d624fbf
Compare
…lop gecos fields According to the Wikipedia page for the 'Gecos field', the "typical" format for the GECOS field is a comma-delimited list with this order: 1) User's full name (or application name, if the account is for a program) 2) Building and room number or contact person 3) Office telephone number 4) Home telephone number 5+) Any other contact information (pager number, fax, external e-mail address, etc.) But our code supported the "other contact information", which we call slop, and which is composed of an arbitrary number of key=value fields, to appear before any of the other 4 fields. This seems to be undocumented, and none of the documentation I've found for the GECOS field in any systems I checked claims to support this. By removing support for those, we can significantly simplify the copy_field() function, which was quite unreadable. After this patch, the GECOS field is treated as a CSV, blindly copying the fields as they appear, where the first 4 fields are as specified above, and anything after them is the slop (5+ fields, any other contact information). Signed-off-by: Alejandro Colomar <alx@kernel.org>
This wrapper was very weird, and it's simpler to open-code the calls to strsep(3) and strcpy(3) instead. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Otherwise, the buffer would contain garbage. Signed-off-by: Alejandro Colomar <alx@kernel.org>
We never use more than BUFSIZ. (And we could use way less than that.) Signed-off-by: Alejandro Colomar <alx@kernel.org>
Use a buffer of the exact size we want, and let SNPRINTF() decide if it fits or not. BTW, the old check seemed to be wrong: it wasn't accounting for the commas in the 80-character limit, but that didn't make much sense. Signed-off-by: Alejandro Colomar <alx@kernel.org>
4ac4300 to
f01f131
Compare
This allows us to split the formation of the string into several s*printf() calls. Shorten comment, to make it fit in one line. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Closed
Member
|
Hm, interesting. Yes, based on the code, I just assumed there were programs that wrote 'other' fields anywhere in the string. But I can't find anything that does. More interesting - the util-linux version of chfn does not allow changing the 'extra' field (as it calls it) at all! So I do think this is safe. |
hallyn
approved these changes
Aug 9, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I finally understood what this function was doing. It was over-engineered, for supporting gecos fields that nobody should be writing in the first place. It was also bogus: if the gecos field was missing some subfield, it left the buffers with garbage. Even more buggy: if any of the first 4 CSV fields contained any '=' in them, those would be appended to the slop, regardless of oflg, which is inconsistent with the last lines, which parse the remaining slop depending on oflg. This code was very broken.
Revisions:
v2
v2b
v2c