Skip to content
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

Modular Input: Error during ValidationDefinition/InputDefinition when no value for parameter is passed #198

Closed
jrobins04 opened this issue Oct 25, 2022 · 11 comments

Comments

@jrobins04
Copy link

jrobins04 commented Oct 25, 2022

I am able to reproduce this using v1.9.1. This issue happens when the user provides no value for a modular input parameter.
https://github.com/splunk/splunk-sdk-java/blob/master/splunk/src/main/java/com/splunk/modularinput/XmlUtil.java textInNode() line number 38:

static String textInNode(Node node, String errorMessage) throws MalformedDataException {
        Node child = node.getFirstChild();
        if (child.getNodeType() != Node.TEXT_NODE) {
            throw new MalformedDataException(errorMessage);
        } else {
            return ((Text)child).getData();
        }
    }

Here, no null check is performed for the child variable. In case when the modular input parameter has no value, child will be null and child.getNodeType() leads to null pointer.

Sample input to --validate-arguments that triggers the error:

<?xml version="1.0" encoding="utf-16"?>
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <server_host>tiny</server_host>
    <server_uri>https://127.0.0.1:8089</server_uri>
    <checkpoint_dir>/opt/splunk/var/lib/splunk/modinputs</checkpoint_dir>
    <session_key>123102983109283019283</session_key>
    <!-- The items element only ever contains one item element -->
    <item name="aaa">
        <param name="param1">value1</param>
        <param name="param_bug"></param>
        <param name="disabled">0</param>
        <param name="index">default</param>
        <param_list name="multiValue">
            <value>value1</value>
            <value>value2</value>
        </param_list>
        <param_list name="multiValue2">
            <value>value3</value>
            <value>value4</value>
        </param_list>
    </item>
</items>

In the above example param_bug has no value (user did not input any value to the modular input parameter), this causes child to be null in the textInNode() method.

Please let me know if you need any other information regarding this issue.

Similar issue was created previously: #122 back in March 2018, but it was closed stating that it could not reproduced.

@ashah-splunk
Copy link
Contributor

@jrobins04 thanks for the detailed steps to reproduce the issue. We are looking into this and update you soon.

@jrobins04
Copy link
Author

@ashah-splunk Hi, any update on this? We have been using a custom splunk java sdk jar with the fix(null check) for this. But, recently our app got flagged for cloud app inspect because we don't use the official version of splunk java sdk. So, this issue is of priority for us, or our app could get removed for splunk cloud.

@ashah-splunk
Copy link
Contributor

ashah-splunk commented Nov 3, 2022

@jrobins04 is null check the only fix or are there any other changes done as well? if so then I would request you to share your fix for this so that we can analyse that option for possible solution.

@jrobins04
Copy link
Author

@ashah-splunk Yes, null check is all what we need in my analysis.

static String textInNode(Node node, String errorMessage) throws MalformedDataException {
        Node child = node.getFirstChild();
        if (child.getNodeType() != Node.TEXT_NODE) {
            throw new MalformedDataException(errorMessage);
        } else {
            return ((Text)child).getData();
        }
    }

Here child variable needs to be checked for null.

@ashah-splunk
Copy link
Contributor

Hi @jrobins04 , we have added the null check for the child as per your suggestion ( ref PR ). would request you to have a look and let us know if anything else needs to be handled. We are planning a new Java SDK release next week.

@jrobins04
Copy link
Author

@ashah-splunk thank you for looking into this with priority.

@jrobins04
Copy link
Author

@ashah-splunk Thanks for looking into this. When are you planning a release for this fix?

@ashah-splunk
Copy link
Contributor

@jrobins04 we are planning a release by end of this week.

@ashah-splunk
Copy link
Contributor

@jrobins04 we have a new Java SDK 1.9.2 release, request you to try with the latest release and let us know if you still face the issue. Thanks!

@ashah-splunk
Copy link
Contributor

Closing the issue as no response received. @jrobins04 please reopen the issue if you still face the problem. Thanks!

@jrobins04
Copy link
Author

@ashah-splunk Thank you for quickly fixing this. I have verified that the bug has been fixed in the latest release. Thanks again !

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

No branches or pull requests

2 participants