{"record":{"id":"abb91cd606537117","repo":"NationalSecurityAgency/ghidra","slug":"bad-characters-in-requested-category-type-abb91c","errorCode":null,"errorMessage":"Bad characters in requested category type","messagePattern":"Bad characters in requested category type","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/protocol/InstallTagRequest.java","lineNumber":51,"sourceCode":"\n\tpublic ResponseInfo installresponse;\n\t\n\tpublic InstallTagRequest() {\n\t\tsuper(\"installtag\");\n\t\ttag_name = \"\";\n\t}\n\t\n\t@Override\n\tpublic void buildResponseTemplate() {\n\t\tif (response == null) {\n\t\t\tresponse = installresponse = new ResponseInfo();\n\t\t}\n\t}\n\t\n\t@Override\n\tpublic void saveXml(Writer fwrite) throws IOException {\n\t\tif (!CategoryRecord.enforceTypeCharacters(tag_name)) {\n\t\t\tthrow new IOException(\"Bad characters in requested category type\");\n\t\t}\n\t\tfwrite.append('<').append(name);\n\t\tfwrite.append('>');\n\t\tfwrite.append(tag_name);\n\t\tfwrite.append(\"</\").append(name).append(\">\\n\");\n\t}\n\n\t@Override\n\tpublic void restoreXml(XmlPullParser parser, LSHVectorFactory vectorFactory) throws LSHException {\n\t\tparser.start(name);\n\t\ttag_name = parser.end().getText();\n\t}\n\n}\n","sourceCodeStart":33,"sourceCodeEnd":66,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/protocol/InstallTagRequest.java#L33-L66","documentation":"Thrown by InstallTagRequest.saveXml when serializing a BSim 'installtag' request whose tag_name fails CategoryRecord.enforceTypeCharacters. That validator permits only letters, digits, space, '.', '_', ':', '/', '(' and ')', and rejects null/empty strings. BSim enforces this because the tag name flows into PostgreSQL/ELASTIC category columns and XML attributes that must stay injection-free and round-trippable.","triggerScenarios":"Constructing an InstallTagRequest, setting tag_name to a value containing characters such as quotes, '<', '>', ';', commas, dashes, or null/empty, then calling saveXml(Writer). Also triggered by an empty or null tag_name since enforceTypeCharacters returns false for both.","commonSituations":"Passing a user-supplied label verbatim into a BSim tag install command. Copying a symbol/function name that contains shell or XML metacharacters. Forgetting to initialize tag_name (it defaults to \"\" which fails).","solutions":["Sanitize tag_name with CategoryRecord.enforceTypeCharacters(tag_name) before populating the request, and reject/clean the input if it returns false.","Strip or replace disallowed characters (e.g. replace '-' and ',' with '_') before assigning tag_name.","Ensure tag_name is non-null and non-empty; the default constructor sets it to \"\" which will always fail.","If the name must contain unusual characters, encode it before install and decode on read."],"exampleFix":"// before\nInstallTagRequest req = new InstallTagRequest();\nreq.tag_name = \"my-tag,1\"; // '-' and ',' not allowed\nreq.saveXml(writer);\n\n// after\nInstallTagRequest req = new InstallTagRequest();\nString name = \"my-tag,1\".replace('-', '_').replace(',', '_');\nif (!CategoryRecord.enforceTypeCharacters(name)) {\n    throw new IllegalArgumentException(\"Invalid tag name: \" + name);\n}\nreq.tag_name = name;\nreq.saveXml(writer);","handlingStrategy":"validation","validationCode":"import ghidra.features.bsim.query.description.CategoryRecord;\n\nboolean valid = tag_name != null\n    && !tag_name.isEmpty()\n    && CategoryRecord.enforceTypeCharacters(tag_name);\nif (!valid) {\n    // reject or sanitize before constructing InstallTagRequest\n    tag_name = tag_name.replaceAll(\"[^A-Za-z0-9 .:_/()]\", \"_\");\n}","typeGuard":"// Java: predicate usable as a guard\nstatic boolean isAcceptableTagName(String s) {\n    return s != null && !s.isEmpty() && CategoryRecord.enforceTypeCharacters(s);\n}","tryCatchPattern":"try {\n    req.saveXml(writer);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Bad characters\")) {\n        // sanitize tag_name and retry once\n        req.tag_name = req.tag_name.replaceAll(\"[^A-Za-z0-9 .:_/()]\", \"_\");\n        req.saveXml(writer);\n    } else throw e;\n}","preventionTips":["Always initialize tag_name to a non-empty, sanitized value rather than the constructor default of \"\".","Run CategoryRecord.enforceTypeCharacters on any user-supplied name before assignment.","Treat symbols with shell/XML metacharacters as needing sanitization before BSim install."],"tags":["bsim","validation","xml","input-validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}