fboss2: guard against unset USER env var in getUnixname#1293
Open
atulya-singh wants to merge 1 commit into
Open
fboss2: guard against unset USER env var in getUnixname#1293atulya-singh wants to merge 1 commit into
atulya-singh wants to merge 1 commit into
Conversation
getenv("USER") can return nullptr (e.g. when USER is not set in the
environment), and getUnixname() passed the result straight to strcmp(),
causing a null-pointer dereference / crash. Guard for nullptr and empty
string before the strcmp calls, matching the handling already done in
getUserInfo() above. An empty/unset USER now falls through to the
interactive prompt.
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
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.
Pre-submission checklist
pip install -r requirements-dev.txt && pre-commit installpre-commit runSummary
getUnixname()infboss/cli/fboss2/utils/CmdUtilsCommon.cppcallsgetenv("USER")and passes the result directly tostrcmp():getenvreturnsnullptrwhen the variable is not set, sostrcmp(nullptr, ...)is a null-pointer dereference and crashes the CLI. This is inconsistent withgetUserInfo()directly above, which already null-checks the result ofgetenv.This change guards for
nullptrand empty string before thestrcmpcalls. An unset or emptyUSERnow falls through to the existing interactive prompt instead of crashing.Test Plan
pre-commit run --files fboss/cli/fboss2/utils/CmdUtilsCommon.cpp->clang-format ... Passed, all hooks pass.USER=alice-> returnsalice(unchanged)USER=root-> falls through to interactive prompt (unchanged)USERunset / empty -> falls through to interactive prompt (previously crashed)