Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RACE: Trim trailing \n when reading top scores. #397

Merged
merged 1 commit into from
Feb 23, 2025

Conversation

dsvensson
Copy link
Collaborator

@dsvensson dsvensson commented Feb 23, 2025

Introduced back in 2011 via 9fc1a31 but hidden thanks to strlcpy incorrectly using source buffer length (and risking buffer overflow). After fe38404 strlcpy was invoked with destination buffer length, and source buffer was copied up until NUL-termination and thus incorrectly included the \n.

Found by @VVD, fixes #388

Introduced back in 2011 via 9fc1a31 but hidden thanks to strlcpy
incorrectly using source buffer length (and risking buffer overflow).
After fe38404 strlcpy was invoked with destination buffer length, and
source buffer was copied up until NUL-termination and thus incorrectly
included the \n.
@dsvensson dsvensson merged commit 5ada24e into QW-Group:master Feb 23, 2025
10 checks passed
@VVD
Copy link

VVD commented Feb 23, 2025

v2 (optimized):

--- src/race.c.orig     2025-02-16 18:01:44 UTC
+++ src/race.c
@@ -3541,10 +3541,9 @@ char* race_fgets(char *buf, int limit)
                return NULL;
        }

-       string = buf;
-       while (--limit > 0 && ((c = race_fgetc()) != -1))
+       for (string = buf; --limit > 0 && (c = race_fgetc()) != -1; string++)
        {
-               if ((*string++ = c) == '\n')
+               if ((*string = c) == '\n')
                {
                        break;
                }

@dsvensson
Copy link
Collaborator Author

@VVD Here's where you create a new PR: https://github.com/QW-Group/ktx/pulls

freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this pull request Feb 23, 2025
The bug that caused version 1.43 to be used when creating the port has
been fixed - the patch has been added to the port.
Upstream pool request: QW-Group/ktx#397

Changelogs:
https://github.com/QW-Group/ktx/releases/tag/v1.44
https://github.com/QW-Group/ktx/releases/tag/1.45
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.

[BUG] Broken race_show_toptimes
2 participants