Skip to content

Modular Input - textInNode throwing exception when input string is empty #122

Closed

Description

@segfault-

Version of this project you're using 1.6.4
Platform version osx 10.13.3 (high sierra)
Framework version java 1.8.0_131
Splunk version 7.0.2 - 03bbabbd5c0f

Other relevant information (ex: local/remote environment, Splunk network configuration)

I tracked down this bug because at surface level, it appeared that input validation was not being executed. Indeed it wasn't being executed because XmlUtil.textInNode would throw an exception when encountering an argument with a null/empty value.

I have a proposed fix below that seems to work on 7.0.2, but i can't speak to backwards compatibility with older versions of splunk

com.splunk.modularinput.XmlUtil.textInNode(XmlUtil.java:38)\com.splunk.modularinput.Parameter.nodeToParameterList(Parameter.java:72)\com.splunk.modularinput.ValidationDefinition.parseDefinition(ValidationDefinition.java:245)\com.splunk.modularinput.Script.run(Script.java:85)\com.splunk.modularinput.Script.run(Script.java:44)...

fix in my env
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();
    
  •    if(child != null) {
    
  •       if (child.getNodeType() != Node.TEXT_NODE) {
    
  •           throw new MalformedDataException(errorMessage);
    
  •       } else {
    
  •           return ((Text)child).getData();
    
  •       }
       }
    
  •    return("");
    
    }

Activity

  1. segfault- commented on Mar 23, 2018

    @segfault-
    Author

    my formatting didn't go thru, i just added a child!=null check

  2. shakeelmohamed commented on Mar 23, 2018

    @shakeelmohamed
    Contributor

    Hi @segfault-, thanks for you note. Feel free to open a pull request if there's a specific change you'd like to see

  3. bparmar-splunk commented on Aug 27, 2021

    @bparmar-splunk
    Contributor

    Hi @segfault-,
    We have checked the usage of XmlUtil.textInNode method in entire SDK code, and has found that null checks are implemented where this method is called.
    We have also executed Validation test, but could not encounter this issue.

    We would recommend to update SDK version to 1.7.1 and make use of JDK 1.8 & maven build, as we have migrated from Ant to Maven.

    Please let us know, if you still face any issue, along with details to reproduce.

  4. jrobins04 commented on Oct 25, 2022

    @jrobins04

    Hi @bparmar-splunk,

    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.

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

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions