How to fix a broken End Gateway in Minecraft Survival?

I don't know if there is a better way to do this, but I worked out the following by looking at Youtube videos about custom portals. It involves using commands, so in survival you have to temporarily enable cheats to do it.

First, make a backup of your entire world directory, in case something goes wrong!

Make a note of the coordinates of the portal(s) that are not working correctly. You can do this very easily using f3 and pointing at the portal. Possibly not quite so easy is to find the coordinates of the return portal. If you can use another portal to travel there you can use f3 in the same way to find its coordinates. Alternatively if you have a backup of your world you may be able to use that to find the right coordinates, or you can find an alternative 'safe' place to point the portal to. You may find @Fabian's tips in the comments below this answer useful to get the coordinates.

Turn on cheats by opening your world to LAN (ESC, then Open to LAN, toggle Allow Cheats: ON and then Start LAN World).

Use the following sequence of commands (coordinates for the portal are x, y, z; coordinates for the destination are m, n, o):

/setblock x y z air 0 replace
/setblock x y z end_gateway 0 replace {ExitPortal:{X:m,Y:n,Z:o},ExactTeleport:0}

The first line deletes the malfunctioning gateway block at x, y, z and replaces it with air. I found this was necessary because I could not directly replace the gateway block with another one. Without this you just get a message to say the block was not placed.

The second line places a new gateway block in the same location, and points it to teleport to coordinates m, n, o, with the 'normal' end gateway behaviour.

Save your game and restart it to close the LAN, and the portal should now work.

If you are unable to find the correct coordinates for the destination, it may be safer to find another place to use as the teleport target, and use ExactTeleport:1.