{"record":{"id":"9844158864b88b96","repo":"NationalSecurityAgency/ghidra","slug":"port-must-be-numeric-984415","errorCode":null,"errorMessage":"port must be numeric","messagePattern":"port must be numeric","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py","lineNumber":170,"sourceCode":"    \"\"\"\n\n    STATE.require_no_client()\n    if address is None:\n        raise RuntimeError(\n            \"'ghidra_trace_connect': missing required argument 'address'\")\n\n    parts = address.split(':')\n    if len(parts) != 2:\n        raise RuntimeError(\"address must be in the form 'host:port'\")\n    host, port = parts\n    try:\n        c = socket.socket()\n        c.connect((host, int(port)))\n        # TODO: Can we get version info from the DLL?\n        STATE.client = Client(c, \"drgn\", methods.REGISTRY)\n        print(f\"Connected to {STATE.client.description} at {address}\")\n    except ValueError:\n        raise RuntimeError(\"port must be numeric\")\n\n\ndef ghidra_trace_listen(address: str = '127.0.0.1:0') -> None:\n    \"\"\"\n    Listen for Ghidra to connect for tracing\n\n    Takes an optional address for the host and port on which to listen.\n    Either the form 'host:port' or just 'port'. If omitted, it will bind\n    to an ephemeral port on localhost. If only the port is given, it will\n    bind to that port on localhost. This command will block until the\n    connection is established.\n    \"\"\"\n\n    STATE.require_no_client()\n    parts = address.split(':')\n    if len(parts) == 1:\n        host, port = '127.0.0.1', parts[0]\n    elif len(parts) == 2:","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py#L152-L188","documentation":"Thrown by ghidra_trace_connect in the drgn agent when the port component of the 'host:port' address string cannot be parsed as an integer. The ValueError from int(port) (or from socket.connect) is caught and re-raised as RuntimeError with this message. This guards the socket connection attempt so a meaningful error reaches the user rather than a raw ValueError traceback.","triggerScenarios":"Calling ghidra_trace_connect('host:abc'), ghidra_trace_connect('127.0.0.1:notaport'), or any address where the substring after the colon is not a base-10 integer. Also fires if the port contains whitespace, a protocol prefix like 'tcp://', or a service name like 'http'.","commonSituations":"Typo in the port string when copy-pasting an address; accidentally including a URL scheme (e.g. 'tcp://host:1234'); using a service name instead of a numeric port; trailing whitespace or newline in a port read from a config file.","solutions":["Ensure the port is a plain base-10 integer in the range 0-65535, e.g. '127.0.0.1:12345'.","Strip any protocol prefix (http://, tcp://) and trailing whitespace from the address string before passing it.","Validate the port substring with int(port_str) in a try/except before calling ghidra_trace_connect."],"exampleFix":"// before\nghidra_trace_connect('localhost:ssh')\n// after\nghidra_trace_connect('localhost:22')","handlingStrategy":"validation","validationCode":"def validate_connect_address(address: str) -> None:\n    parts = address.split(':')\n    if len(parts) != 2:\n        raise ValueError(f\"Address must be 'host:port', got: {address}\")\n    host, port = parts\n    try:\n        p = int(port)\n        if not (0 <= p <= 65535):\n            raise ValueError(f\"Port out of range: {p}\")\n    except ValueError:\n        raise ValueError(f\"Port must be numeric (0-65535), got: {port}\")\n\n# Call before ghidra_trace_connect:\nvalidate_connect_address(address)","typeGuard":null,"tryCatchPattern":"try:\n    ghidra_trace_connect(address)\nexcept RuntimeError as e:\n    if 'port must be numeric' in str(e):\n        print(f\"Invalid port in address '{address}'. Use 'host:port' with a numeric port.\")\n    else:\n        raise","preventionTips":["Always validate the address string with a host:port regex before passing to ghidra_trace_connect.","When reading the address from user input or config, strip whitespace and reject protocol prefixes.","Provide a default port in configuration so empty values never reach the parser."],"tags":["network","input-validation","drgn","address-parsing"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}