Skip to content

fix: handle null path parameter in RestNodesCapabilitiesAction and pr… #113413

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 5 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: handle null path parameter in RestNodesCapabilitiesAction and pr…
…event NPE

- Added null check for the 'path' parameter in RestNodesCapabilitiesAction to avoid NullPointerException.
- If 'path' is not provided, assign an empty string to ensure safe handling in the URLDecoder and other parts of the code.
- Updated the response to return a valid node capabilities result with a successful outcome.
- Ensured the request behaves properly when no path is provided, preventing crashes.
  • Loading branch information
nbenliogludev committed Sep 23, 2024
commit 9796c9944a8f86da3bc07bc163efa50c41652a47
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,26 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
? new NodesCapabilitiesRequest(client.getLocalNodeId())
: new NodesCapabilitiesRequest();

// Handle the 'path' parameter safely, assign an empty string if null
String path = request.param("path");
if (path != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of checking for null, we can just use the default value parameter:

.path(request.param("path", "/"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @thecoop,

I've made the requested change to use request.param("path", "/") as the default value for the path parameter instead of checking for null. Please let me know if there are any further adjustments needed.

Thank you!

path = URLDecoder.decode(path, StandardCharsets.UTF_8);
} else {
path = ""; // Assign an empty string to avoid any null pointer issues
}

NodesCapabilitiesRequest r = requestNodes.timeout(getTimeout(request))
.method(RestRequest.Method.valueOf(request.param("method", "GET")))
.path(URLDecoder.decode(request.param("path"), StandardCharsets.UTF_8))
.path(path) // Pass the safely decoded path (or empty string)
.parameters(request.paramAsStringArray("parameters", Strings.EMPTY_ARRAY))
.capabilities(request.paramAsStringArray("capabilities", Strings.EMPTY_ARRAY))
.restApiVersion(request.getRestApiVersion());

return channel -> client.admin().cluster().nodesCapabilities(r, new NodesResponseRestListener<>(channel));
}



@Override
public boolean canTripCircuitBreaker() {
return false;
Expand Down