Ns_socket_get_id generates always empty string on linux (#1248)
Some checks are pending
Build coop / build-linux (push) Waiting to run
Build coop / build-steamos (push) Waiting to run
Build coop / build-windows (push) Waiting to run
Build coop / build-macos-arm (push) Waiting to run
Build coop / build-macos-intel (push) Waiting to run

This pr fixes an issue on linux where the function ns_socket_get_id_str always returns empty string.
See glibc implementation of vsnprintf : [vsnprintf implementation](https://elixir.bootlin.com/glibc/glibc-2.36/source/libio/vsnprintf.c#L112). First string parameter is "emptied" before starting the copy.

And I suspect the original snprintf to rewrite twice the same value in id_str (except if I missed something) so we can just remove it.

This issue gives moderator access to all players when they connect/reconnect after adding one player as moderator because all players have the same id : "".

How to reproduce : 
Host server (via socket, not coopnet) on sm64coopdx linux version
Add moderator to one player
All new connected or reconnected player are promoted to moderator
This commit is contained in:
fefux 2026-05-17 23:58:46 +02:00 committed by GitHub
parent ac03a9c0da
commit 87f87b5dc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -201,7 +201,7 @@ static s64 ns_socket_get_id(UNUSED u8 localId) {
static char* ns_socket_get_id_str(u8 localId) {
if (localId == UNKNOWN_LOCAL_INDEX) { localId = 0; }
static char id_str[INET6_ADDRSTRLEN] = { 0 };
snprintf(id_str, INET6_ADDRSTRLEN, "%s", inet_ntop(AF_INET6, &sAddr[localId].sin6_addr, id_str, sizeof(id_str)));
inet_ntop(AF_INET6, &sAddr[localId].sin6_addr, id_str, sizeof(id_str));
return id_str;
}