Skip to content

Conversation

@cbuescher
Copy link
Member

I found the first UserException thrown in #execute marked as dead code when
accidentally switching this from a warning to an error. It looks like the output
of FileUserPasswdStore.parseFile a line above shouldn't be wrapped into another
map since its output can be null. Looking at Commit fab5e21 I wonder what
changed this back? The history of this file is a bit unclear to me, but I think
L225 should be changed.

I found the first UserException thrown in #execute marked as dead code when
accidentally switching this from a warning to an error. It looks like the output
of FileUserPasswdStore.parseFile a line above shouldn't be wrapped into another
map since its output can be null. Looking at Commit fab5e21 I wonder what
changed this back? The history of this file is a bit unclear to me, but I think
L225 should be changed.
@cbuescher cbuescher added >bug v7.0.0 :Security/Security Security issues without another label labels Jan 21, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(file, null, env.settings()));
Map<String, char[]> users = FileUserPasswdStore.parseFile(file, null, env.settings());
if (users == null) {
throw new UserException(ExitCodes.CONFIG, "Configuration file [" + file + "] is missing");
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently this looks dead. Furthermore, FileUserPasswdStore.parseFile can return null which I think will then create an NPE in the HashMap ctor.

throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
}
final Hasher hasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(env.settings()));
users = new HashMap<>(users); // make modifiable
Copy link
Member Author

Choose a reason for hiding this comment

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

same approach as in L129

@cbuescher
Copy link
Member Author

@elasticmachine run elasticsearch-ci/2

@jaymode jaymode self-requested a review January 22, 2019 15:37
Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

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

LGTM. Nice catch

@jaymode
Copy link
Member

jaymode commented Jan 22, 2019

@cbuescher this also looks like a issue in 6.x. Do you mind backporting to 6.x and 6.6?

@cbuescher cbuescher merged commit 256e01c into elastic:master Jan 22, 2019
cbuescher pushed a commit that referenced this pull request Jan 22, 2019
It looks like the output of FileUserPasswdStore.parseFile shouldn't be wrapped 
into another map since its output can be null. Doing this wrapping after the null
check (which potentially raises an exception) instead.
cbuescher pushed a commit that referenced this pull request Jan 22, 2019
It looks like the output of FileUserPasswdStore.parseFile shouldn't be wrapped 
into another map since its output can be null. Doing this wrapping after the null
check (which potentially raises an exception) instead.
@cbuescher cbuescher deleted the possibly-dead-code branch November 27, 2025 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants