{"record":{"id":"76d2efd281cc85c6","repo":"NationalSecurityAgency/ghidra","slug":"bsim-url-missing-db-name-path","errorCode":null,"errorMessage":"BSim URL missing DB name/path","messagePattern":"BSim URL missing DB name/path","errorType":"validation","errorClass":"MalformedURLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimClientFactory.java","lineNumber":58,"sourceCode":"\t\tcheckBSimServerURL(url);\n\t\treturn url;\n\t}\n\n\t/**\n\t * Validate BSim DB URL.\n\t * Acceptable protocols are  postgresql://  https://,  (or possibly http://) file:/\n\t * @param url BSim DB URL\n\t * @throws MalformedURLException if the URL string is not a support BSim DB URL\n\t */\n\tpublic static void checkBSimServerURL(URL url) throws MalformedURLException {\n\t\tString protocol = url.getProtocol();\n\t\tif (!protocol.equals(\"postgresql\") && !protocol.equals(\"https\") &&\n\t\t\t!protocol.equals(\"elastic\") && !protocol.equals(\"file\")) {\n\t\t\tthrow new MalformedURLException(\"Protocol not permissable for BSim URL\");\n\t\t}\n\t\tString path = url.getPath();\n\t\tif (path == null || path.length() == 0 || path.equals(\"/\")) {\n\t\t\tthrow new MalformedURLException(\"BSim URL missing DB name/path\");\n\t\t}\n\t\tif (!\"file\".equals(protocol) && path.indexOf('/', 1) >= 0) {\n\t\t\tthrow new MalformedURLException(\"BSim URL must specify exactly 1 path element\");\n\t\t}\n\t}\n\n\t/**\n\t * Construct the root URL to a specific BSim repository given a \"related\" URL.\n\t * The root URL will have an explicit protocol, a hostname + other mods (the authority), and 1 level of path\n\t *    this first level path indicates the particular repository being referenced on the host.\n\t * The \"related\" URL -url- can be an explicitly provided URL pointing to the BSim repository,\n\t *    possibly with additional path levels, which are simply stripped from the final root URL.\n\t * Alternately -url- can reference a ghidra server, as indicated by the \"ghidra\" protocol.\n\t *    In this case the true BSim URL is derived from ghidra URL in some way\n\t * @param urlString is the \"related\" URL\n\t * @return the root BSim URL\n\t * @throws MalformedURLException if the given URL string cannot be parsed\n\t * @throws URISyntaxException if the given URL string cannot be parsed","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimClientFactory.java#L40-L76","documentation":"checkBSimServerURL() validates that the URL has a non-empty path that isn't just '/' — the path represents the database name. If path is null, empty, or equals '/' the MalformedURLException is thrown because BSim requires a database identifier in the URL path.","triggerScenarios":"Calling checkBSimServerURL(url) where url.getPath() is null, has length 0, or equals '/'. E.g., 'postgresql://myhost' or 'postgresql://myhost/' without a database name.","commonSituations":"User omits the database name from the URL (provides only host); trailing slash without a name; URL was constructed programmatically and the path component was dropped; user expected the database name to come from a query parameter or default.","solutions":["Append the database name as the path: e.g., 'postgresql://myhost/bsimdb' instead of 'postgresql://myhost'.","Ensure the URL construction code includes the database/repository name in the path component.","Remove a bare trailing '/' and replace it with the actual database name."],"exampleFix":"// before\nString url = \"postgresql://myhost\"; // missing DB name\n//\n// after\nString url = \"postgresql://myhost/bsimdb\";","handlingStrategy":"validation","validationCode":"String path = url.getPath();\nif (path == null || path.isEmpty() || path.equals(\"/\")) {\n    // Require a database name in the path\n    throw new IllegalArgumentException(\n        \"BSim URL must include a database name in the path, e.g., postgresql://host/dbname\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    BSimClientFactory.checkBSimServerURL(url);\n} catch (MalformedURLException e) {\n    if (e.getMessage().contains(\"missing DB name\")) {\n        // prompt user for database name\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always include the database name as the first path segment in BSim URLs.","Validate URL construction includes a non-empty path.","Provide URL templates with a placeholder for the database name in documentation."],"tags":["bsim","url-validation","configuration","database-name"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}