FreeOpcUa / python-opcua

LGPL Pure Python OPC-UA Client and Server
http://freeopcua.github.io/
GNU Lesser General Public License v3.0
1.33k stars 660 forks source link

Server doesn't handle empty BrowsePath #1265

Open Pascal-So opened 3 years ago

Pascal-So commented 3 years ago

Describe the bug
The server-methods.py example encounters an out of range error.

Traceback (most recent call last):
  File "/home/gea/.local/lib/python3.8/site-packages/opcua/server/binary_server_asyncio.py", line 75, in _process_data
    ret = self.processor.process(hdr, buf)
  File "/home/gea/.local/lib/python3.8/site-packages/opcua/server/uaprocessor.py", line 93, in process
    return self.process_message(msg.SequenceHeader(), msg.body())
  File "/home/gea/.local/lib/python3.8/site-packages/opcua/server/uaprocessor.py", line 113, in process_message
    return self._process_message(typeid, requesthdr, seqhdr, body)
  File "/home/gea/.local/lib/python3.8/site-packages/opcua/server/uaprocessor.py", line 269, in _process_message
    paths = self.session.translate_browsepaths_to_nodeids(params.BrowsePaths)
  File "/home/gea/.local/lib/python3.8/site-packages/opcua/server/internal_server.py", line 369, in translate_browsepaths_to_nodeids
    return self.iserver.view_service.translate_browsepaths_to_nodeids(params)
  File "/home/gea/.local/lib/python3.8/site-packages/opcua/server/address_space.py", line 147, in translate_browsepaths_to_nodeids
    results.append(self._translate_browsepath_to_nodeid(path))
  File "/home/gea/.local/lib/python3.8/site-packages/opcua/server/address_space.py", line 153, in _translate_browsepath_to_nodeid
    if not path.RelativePath.Elements[-1].TargetName:
IndexError: list index out of range

OPC Router then complains about a timeout error because it didn't get a response to the TranslateBrowsePathsToNodeIdsRequest.

To Reproduce

Run the server-methods.py example and access the server using "OPC Router Version 4.18 - Trial version". The client then eventually sends a "TranslateBrowsePathsToNodeIdsRequest" with an empty array of RelativePathElement (according to wireshark), which causes the error to be printed to the server console.

Expected behavior
I'm not sure if this empty path is allowed by the spec, and a comment in the server source also mentions this, but apparently this appears in the real world, whether or not it is valid by spec, so I guess this should be handled.

Version
Python-Version: 3.8.5 python-opcua Version: 0.98.12 OPC Router Version 4.18 - Trial version

dagsonpatrick commented 3 months ago

Hello @Pascal-So , I have the same problem as you. Were you able to resolve this issue? If so, could you help me, thank you!

Pascal-So commented 3 months ago

Hi @dagsonpatrick, unfortunately I wasn't able to fix this issue. If I remember correctly, this was around the time when I was switching everything over to rust anyway, and I've had good experiences with the locka99/opcua library in rust in different projects ever since.

Note however that I don't remember if I've ever done anything with OPC Router again afterwards, so maybe the same problem still remains, I can't make any guarantees about that.