{"record":{"id":"9dd7ac8230199c63","repo":"NationalSecurityAgency/ghidra","slug":"port-must-be-numeric-9dd7ac","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-x64dbg/src/main/py/src/ghidraxdbg/commands.py","lineNumber":182,"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, \"x64dbg\", 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    \"\"\"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:\n        host, port = parts","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-x64dbg/src/main/py/src/ghidraxdbg/commands.py#L164-L200","documentation":"Raised by ghidra_trace_connect (commands.py:181-182) from the except ValueError clause wrapping int(port). The split produced two parts (so the form check passed) but the port token is not a base-10 integer, so int(port) raises ValueError which is converted into this RuntimeError.","triggerScenarios":"Calling ghidra_trace_connect('host:abc'), 'host:0x80' (hex not accepted by int base 10), 'host:' (empty port), or 'host:12.5' (non-integer).","commonSituations":"User enters a service name instead of a port number; copies a hex offset; trailing whitespace in the port token; a port field that allowed free text.","solutions":["Use a decimal integer port, e.g. '127.0.0.1:12345'.","Strip whitespace and validate isdigit() on the port token before calling.","Convert hex input to decimal first if the source is hexadecimal."],"exampleFix":"// before\nghidra_trace_connect('127.0.0.1:0x50')\n\n// after\nghidra_trace_connect('127.0.0.1:80')","handlingStrategy":"validation","validationCode":"host, _, port = address.rpartition(':')\nif not port.isdigit():\n    raise ValueError(f'port must be numeric, got {port!r}')\nghidra_trace_connect(f'{host}:{int(port)}')","typeGuard":"def port_is_numeric(address: str) -> bool:\n    port = address.rpartition(':')[2]\n    return port.isdigit()","tryCatchPattern":"try:\n    ghidra_trace_connect(address)\nexcept RuntimeError as e:\n    if 'port must be numeric' in str(e):\n        raise ValueError(f'Please enter a numeric port in {address}') from e\n    raise","preventionTips":["Restrict the port input field to digits only.","Strip whitespace from the port token before calling.","Convert hex input to decimal upstream."],"tags":["connect","argument-validation","port-parsing","python"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}