Skip to content

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

Closed

Description

@jrobins04

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.

Activity

  1. ashah-splunk commented on Oct 27, 2022

    @ashah-splunk
    Contributor

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

  2. jrobins04 commented on Oct 31, 2022

    @jrobins04
    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.

  3. ashah-splunk commented on Nov 3, 2022

    @ashah-splunk
    Contributor

    @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.

  4. jrobins04 commented on Nov 3, 2022

    @jrobins04
    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.

  5. ashah-splunk commented on Nov 11, 2022

    @ashah-splunk
    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.

  6. jrobins04 commented on Nov 12, 2022

    @jrobins04
    Author

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

  7. jrobins04 commented on Nov 15, 2022

    @jrobins04
    Author

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

  8. ashah-splunk commented on Nov 16, 2022

    @ashah-splunk
    Contributor

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

  9. ashah-splunk commented on Nov 18, 2022

    @ashah-splunk
    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!

  10. ashah-splunk commented on Dec 12, 2022

    @ashah-splunk
    Contributor

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

  11. jrobins04 commented on Dec 14, 2022

    @jrobins04
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions