{"record":{"id":"bdbf5175afe840cc","repo":"NationalSecurityAgency/ghidra","slug":"missing-databasename-for-drop-database","errorCode":null,"errorMessage":"Missing databaseName for drop database","messagePattern":"Missing databaseName for drop database","errorType":"validation","errorClass":"LSHException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/AbstractSQLFunctionDatabase.java","lineNumber":2103,"sourceCode":"\t\t\tFunctionDescription func =\n\t\t\t\tqueryByNameAddress(response.manage, exe, entry.funcName, entry.address, true);\n\t\t\tif (func == null) {\n\t\t\t\tthrow new LSHException(\"Could not find function: \" + entry.funcName);\n\t\t\t}\n\t\t\tresponse.correspond.add(func);\n\t\t}\n\n\t\tTreeMap<RowKey, FunctionDescription> funcmap = new TreeMap<>();\n\t\tresponse.manage.generateFunctionIdMap(funcmap);\n\t\tfor (FunctionDescription element : response.correspond) {\n\t\t\tfillinChildren(element, response.manage, funcmap);\n\t\t}\n\t}\n\n\tprivate void fdbDatabaseDrop(DropDatabase query) throws LSHException {\n\t\tResponseDropDatabase response = query.getResponse();\n\t\tif (query.databaseName == null) {\n\t\t\tthrow new LSHException(\"Missing databaseName for drop database\");\n\t\t}\n\t\tif (!query.databaseName.equals(ds.getServerInfo().getDBName())) {\n\t\t\tthrow new UnsupportedOperationException(\"drop database name must match\");\n\t\t}\n\t\tresponse.dropSuccessful = true;\t\t// Response parameters assuming success\n\t\tresponse.errorMessage = null;\n\t\ttry {\n\t\t\tdropDatabase();\n\t\t}\n\t\tcatch (SQLException e) {\n\t\t\tString msg = e.getMessage();\n\t\t\tif (msg.indexOf(\"database \\\"\" + query.databaseName + \"\\\" does not exist\") > 0) {\n\t\t\t\treturn; // missing database\n\t\t\t}\n\t\t\tresponse.dropSuccessful = false;\n\t\t\tresponse.errorMessage = e.getMessage();\n\t\t}\n\t}","sourceCodeStart":2085,"sourceCodeEnd":2121,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/AbstractSQLFunctionDatabase.java#L2085-L2121","documentation":"`fdbDatabaseDrop` requires `query.databaseName` to be non-null. If it is null, LSHException is thrown before any drop is attempted. This is required-field validation for the DropDatabase command; immediately after, the name must also match the connected DB's name or UnsupportedOperationException fires.","triggerScenarios":"Issuing a DropDatabase request without setting databaseName (left null from construction, deserialization, or a builder that skipped the field).","commonSituations":"Programmatic command construction omitting required fields; deserialization gaps from a malformed request; copy-paste of a command template without filling the name.","solutions":["Set query.databaseName to the target database name before dispatching.","Validate the DropDatabase command object (non-null name, and name matches the connection) before sending.","Use a builder that enforces required fields."],"exampleFix":"// before\nDropDatabase cmd = new DropDatabase();\ncmd.databaseName = null;                  // throws\n// after\nDropDatabase cmd = new DropDatabase();\ncmd.databaseName = \"my_bsim_db\";","handlingStrategy":"validation","validationCode":"// Require a non-null, matching database name before dropping.\nif (query.databaseName == null) {\n    throw new IllegalArgumentException(\"DropDatabase requires databaseName\");\n}\nif (!query.databaseName.equals(ds.getServerInfo().getDBName())) {\n    throw new IllegalArgumentException(\"databaseName must match the connected DB\");\n}","typeGuard":"// isDropRequestValid: true iff databaseName is set and matches the connection.\nstatic boolean isDropRequestValid(DropDatabase q, DataSource ds) {\n    return q.databaseName != null\n        && q.databaseName.equals(ds.getServerInfo().getDBName());\n}","tryCatchPattern":"try {\n    db.fdbDatabaseDrop(query);\n} catch (LSHException e) {\n    if (e.getMessage().equals(\"Missing databaseName for drop database\")) {\n        throw new IllegalArgumentException(\"Set query.databaseName before drop\", e);\n    }\n    throw e;\n}","preventionTips":["Validate the DropDatabase command (non-null name, matches connection) before dispatch.","Use a builder that enforces required fields.","Null-check command objects at the dispatch boundary."],"tags":["validation","api-usage","database","drop","bsim"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}