emsec / hal

HAL – The Hardware Analyzer
MIT License
530 stars 72 forks source link

Segfault when replacing net destination in python API #547

Open MonsterDruide1 opened 7 months ago

MonsterDruide1 commented 7 months ago

Describe the bug When running a script in the python console that replaces (remove and add) the connection to nets on one pin, HAL crashes with a segfault.

To Reproduce Steps to reproduce the behavior:

  1. Open any netlist with at least one gate
  2. Get the ID of any net with at least one destination
  3. Run the following script:
    net = netlist.get_net_by_id(ID_FROM_EARLIER)
    g = net.get_destinations()[0]
    net.remove_destination(g)
    net.add_destination(g.get_gate(), g.get_pin())

Expected behavior HAL should not crash. Visually/technically, nothing should happen, as we're replacing the net with the same net in this example. This is used in practice for replacing the input of one gate with a different net.

On that note, it might be helpful if some additional info for the requirements of add_destination would be listed in the documentation. For example, that the destination endpoint should not have an existing connection, which would need to be removed before like this.

Desktop (please complete the following information):

Additional context Might be required in the Project 4 of the Hardware-Reverse-Engineering course held at RUB.

joern274 commented 6 months ago

In your script g is the endpoint of the net you are about to remove. Please keep in mind that you cannot extract any information from that endpoint after removal.

After the following modification your script works for me (ep = EndPoint, g = Gate, pn = Pin)

net = netlist.get_net_by_id(34)
ep = net.get_destinations()[0]
g = ep.get_gate() # get gate before removing endpoint
pn = ep.get_pin() # get pin before removing endpoint
net.remove_destination(ep)
net.add_destination(g,pn)