Skip to content

Server: fix buggy configstring transmission - #1218

Merged
slipher merged 2 commits into
DaemonEngine:masterfrom
slipher:bcs
Jul 22, 2024
Merged

slipher merged 2 commits into
DaemonEngine:masterfrom
slipher:bcs

Conversation

@slipher

@slipher slipher commented Jul 7, 2024

Copy link
Copy Markdown
Member

The bug is described in #1215.


static void SendConfigStringToClient( int cs, client_t *cl )
{
char buf[ 1024 ]; // escaped characters, in a quoted context

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MAX_STRING_CHARS constant?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The immediately relevant limit here is 1022 which is hard-coded in SV_SendServerCommand. I added a comment about this. I don't believe any buffer declared with size MAX_STRING_CHARS is involved anywhere in the stack.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't exactly understand the comment, but I guess that means that 1022 + " + "?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it really only needs to be 2 or 3 char longer than limit.

Comment thread src/engine/server/sv_init.cpp Outdated
The bcs0, bcs1, and bcs2 commands are used to transmit an info string
that has more than a certain length. The old code chopped them into
pieces based on the original length rather than the escaped length and
provided only a fixed amount of overhead for escape characters. Turns
out the overhead wasn't enough for real-life use cases (there are a lot
of backslashes due to infostring separators) and so the command to send
the serverinfo configstring would sometimes overflow and be silently
dropped.

Fix this by chopping up the string based on the escaped length.
Comment on lines +88 to +89
// max command size for SV_SendServerCommand is 1022, leave a little overhead for the command
char *limit = buf + 990;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the cs chunking code uses 1024 - 64 as the size. Does it make sense to be consistent with that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

@DolceTriade DolceTriade left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but didn't test % a few questions. Maybe Kai can test this out?

@cu-kai

cu-kai commented Jul 7, 2024

Copy link
Copy Markdown
Contributor

This does seem to fix it, however I saw an instance of:
Warn: CG_AddPlayerWeapon: weapon 0 (<nullptr>) is not registered

I only saw this once, and could not reproduce it.

@DolceTriade

Copy link
Copy Markdown
Contributor

Warn: CG_AddPlayerWeapon: weapon 0 () is not registered

I saw this on my server too but only when I played the td map. I'm unsure if it is related to this issue.

@cu-kai

cu-kai commented Jul 7, 2024

Copy link
Copy Markdown
Contributor

Yes, also on td only on bunker. Haven't seen it since.

@VReaperV

VReaperV commented Jul 8, 2024

Copy link
Copy Markdown
Contributor

I've seen either this or very similar message before (not on td), I think it was on mission-control, way before this change.

@slipher
slipher merged commit e9ac890 into DaemonEngine:master Jul 22, 2024
@slipher
slipher deleted the bcs branch July 22, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants