{"record":{"id":"eb2a7cad2d46738b","repo":"NationalSecurityAgency/ghidra","slug":"negative-value-not-permitted-for","errorCode":null,"errorMessage":"Negative value not permitted for {}","messagePattern":"Negative value not permitted for (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java","lineNumber":370,"sourceCode":"\t\t}\n\t}\n\n\tprivate void checkRequiredParam(String[] params, int index, String name) {\n\t\tif (params.length <= index) {\n\t\t\tthrow new IllegalArgumentException(\"Missing required parameter: \" + name);\n\t\t}\n\t\tString p = params[index];\n\t\tif (p.startsWith(\"--\")) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Missing required parameter (\" + name + \") before specified option: \" + p);\n\t\t}\n\t}\n\n\tprivate int parsePositiveIntegerOption(String option, String optionValue) {\n\t\ttry {\n\t\t\tint value = Integer.valueOf(optionValue);\n\t\t\tif (value < 0) {\n\t\t\t\tthrow new IllegalArgumentException(\"Negative value not permitted for \" + option);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcatch (NumberFormatException e) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid integer value specified for \" + option);\n\t\t}\n\t}\n\n\t/**\n\t * Verify that the given file is a PEM certificate\n\t * @param testFile the file to test\n\t * @return true if testFile looks like a PEM certificate\n\t * @throws IOException if there is a problem reading the given file\n\t */\n\tprivate static boolean verifyPEMFormat(File testFile) throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new FileReader(testFile));\n\t\ttry {\n\t\t\t// All we currently do is search for the certificate header in the first 200 lines","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java#L352-L388","documentation":"Thrown by parsePositiveIntegerOption when an integer option (e.g. --port) parses successfully via Integer.valueOf but the result is less than zero. The guard explicitly rejects negative values.","triggerScenarios":"Passing a negative integer such as `--port -1` or `--port -5`, which Integer.valueOf accepts but fails the `value < 0` check at line 370.","commonSituations":"Accidental leading minus, a signed value sourced from a variable/macro, or an off-by-one producing -1.","solutions":["Use a non-negative integer (the check allows 0 despite the method name).","For ports prefer 1024–65535; verify the source of the value.","Strip any stray minus sign from computed values before passing them."],"exampleFix":"// before\nbsim control configure host --port -5\n// after\nbsim control configure host --port 5432","handlingStrategy":"validation","validationCode":"// Reject negative integers for port-like options before launch.\ntry {\n    int v = Integer.parseInt(portValue);\n    if (v < 0) {\n        System.err.println(\"Negative value not allowed: \" + v);\n        return;\n    }\n} catch (NumberFormatException ignored) {\n    System.err.println(\"Not an integer: \" + portValue);\n}","typeGuard":null,"tryCatchPattern":"try {\n    launchable.parsePositiveIntegerOption(option, value);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Negative value not permitted\")) {\n        System.err.println(\"Use a non-negative integer for \" + option);\n    }\n    throw e;\n}","preventionTips":["Bound-check integers (>= 0, or a sensible port range) before passing them.","Strip accidental minus signs from computed values.","Note the tool allows 0 despite the method name 'Positive'."],"tags":["cli","argument-validation","bsim"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}