tpoechtrager / wc-ng

WC-NG - Cube 2: Sauerbraten Modification
Other
21 stars 3 forks source link

player1's name gets weird #13

Open sauerbraten opened 3 years ago

sauerbraten commented 3 years ago

Raze reported on Discord that his name yesterday showed up wrong for other players: it had strange characters appended to it. To him, the name looked normal.

I confirmed different wonky names were seen on different servers using CHEF: Screenshot 2021-06-24 at 18-28-04 raze – CHEF

I looked into the wc-ng code a bit, especially all the places where player1->name is accessed, and found this line, which runs via client::switchname() and mod::chat::updatename(): https://github.com/tpoechtrager/wc-ng/blob/d5ba6bd32feb00a83a1f22ee37dab7a42ea0be3f/src/mod/chat.cpp#L586

The operator overloading looks fine to me (a C++ noob), in that it copies the string over, however, there is some dense logic when setting the length argument that's passed to memcpy() later. Could you check if you can see a bug here? https://github.com/tpoechtrager/wc-ng/blob/d5ba6bd32feb00a83a1f22ee37dab7a42ea0be3f/src/mod/strtool.h#L85

Somehow, it looks like some buggy code moves the NUL byte Sauer uses to find the string's end when sending the player's name on connect. (Note how there is only one weird name per server.)

I'm not 100% sure how that could explain him seeing the name rendered correctly, since the UI field should show whatever is stored in player1->name... maybe you have an idea? (When I asked Raze, he said he didn't use wc-ng's chat features yesterday when it happened.)

tpoechtrager commented 2 years ago

I can't find an issue with valgrind. Maybe a compiler bug. Let me know if the issue is still present with latest build.