"WG Import" function odd behaviour

Blank or random input filename generates wg interfaces with randomized key pairs and (sometimes)odd port numbers.
I ran into this accidentally.
Tested with Winbox 3.41 and 4.0b16. On a hEX E50UG and a CHR x86 - both on RouterOS v7.17.

Steps to reproduce effect:

  1. In Winbox select the WireGuard menu.
  2. In the WireGuard tab, click the WG Import button.
  3. In the WG Import sub window, leave the File Name: field blank and hit WG Import.

You now have a new wireguard “wg#” interface with a randomly generated keypair and listen port number.
Continuing to do so makes new interfaces with sequentially increasing “wg#” names and a random port.
What’s odd is that it came up with some very low numbers listen ports such as 62 in one case.
Further testing revealed that you can enter any random characters in the File Name: field and you get the same behaviour.

Try in the CLI and you’ll get a random one if you supply the wg-import command with file=“” , but repeating this command only creates the same keypair and port.
Example: /interface/wireguard/wg-import file=“”