Repository: godot
Issue: Crash when resolving IP address from hostname on macOS
Labels: bug,platform:macos,needs testing,topic:network,crash

### Godot version

Happens on The Mirror's fork of Godot, it's hard to reproduce so unsure about master but seems likely given there are not a ton of differences.

### System information

macOS 13.4.1 on M1 Pro

### Issue description

I am getting a crash on macOS when resolving IP addresses from hostnames using the macOS `getaddrinfo` method.

```
================================================================
handle_crash: Program crashed with signal 11
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] 1   libsystem_platform.dylib            0x0000000184362a24 _sigtramp + 56
[2] 2   Network                             0x000000018afd0e74 nw_path_snapshot_path + 48
[3] 3   Network                             0x000000018afd07b8 nw_path_evaluator_evaluate + 2832
[4] 4   Network                             0x000000018afcf5d4 nw_path_create_evaluator_for_endpoint + 108
[5] 5   Network                             0x000000018ae3e594 nw_nat64_v4_address_requires_synthesis + 252
[6] 6   libsystem_info.dylib                0x000000018437f23c _gai_nat64_second_pass + 280
[7] 7   libsystem_info.dylib                0x000000018436bca4 si_addrinfo + 1220
[8] 8   libsystem_info.dylib                0x000000018436b738 getaddrinfo + 168
[9] IPUnix::_resolve_hostname(List<IPAddress, DefaultAllocator>&, String const&, IP::Type) const (in godot.macos.editor.arm64) + 140
[10] IP::resolve_hostname_queue_item(String const&, IP::Type)
[11] _IP_ResolverPrivate::_thread_function(void*) (in godot.macos.editor.arm64) + 92
[12] Thread::callback(unsigned long long, Thread::Settings const&, void (*)(void*), void*) (in godot.macos.editor.arm64) + 120
[13] Thread::~Thread()
[14] 14  libsystem_pthread.dylib             0x0000000184333fa8 _pthread_start + 148
[15] 15  libsystem_pthread.dylib             0x000000018432eda0 thread_start + 8
-- END OF BACKTRACE --
```

The crashing code is [here](https://github.com/godotengine/godot/blob/master/drivers/unix/ip_unix.cpp#L104):

```cpp
	hints.ai_flags &= ~AI_NUMERICHOST;

	// before crash
	int s = getaddrinfo(p_hostname.utf8().get_data(), nullptr, &hints, &result);
	// after crash
	if (s != 0) {
		print_verbose("getaddrinfo failed! Cannot resolve hostname.");
		return;
	}
```

I have used print statements to verify that the `p_hostname.utf8().get_data()` value we are passing in is indeed a valid string. My suspicion is that this is a bug with macOS, but I am not sure. Even if this is a bug in macOS, it may be helpful to have an issue open to track this bug.

### Steps to reproduce

Call this method on macOS and it will randomly crash. It only happens a tiny fraction of the time, a few percent or less, so unfortunately it's very hard to reproduce.

### Minimal reproduction project

Unfortunately since it's so hard to reproduce, I have not been able to reproduce the crash once with the minimal reproduction project (either using master or The Mirror's fork), but here is an attempt at a minimal reproduction project anyway: [IP_resolver_getaddrinfo_crash.zip](https://github.com/godotengine/godot/files/12371524/IP_resolver_getaddrinfo_crash.zip)

Since `IPUnix` is not exposed you also need to use [these engine changes](https://github.com/aaronfranke/godot/tree/ipunix). If you instead use `IP` directly then it will cache the result so the test will only run on one frame.