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

[BUG] Correction of use strlcpy - potencial security issue #287

Open
VVD opened this issue Jan 1, 2023 · 1 comment
Open

[BUG] Correction of use strlcpy - potencial security issue #287

VVD opened this issue Jan 1, 2023 · 1 comment
Labels

Comments

@VVD
Copy link

VVD commented Jan 1, 2023

--- a/src/race.c
+++ b/src/race.c
@@ -3566,9 +3566,9 @@ void read_topscores(void)
                        race_fgets(line, MAX_TXTLEN);
                        race.records[cnt].time = atof(line);
                        race_fgets(line, MAX_TXTLEN);
-                       strlcpy(race.records[cnt].racername, line, strlen(line));
+                       strlcpy(race.records[cnt].racername, line, sizeof(race.records[0].racername));
                        race_fgets(line, MAX_TXTLEN);
-                       strlcpy(race.records[cnt].demoname, line, strlen(line));
+                       strlcpy(race.records[cnt].demoname, line, sizeof(race.records[0].demoname));
                        race_fgets(line, MAX_TXTLEN);
                        race.records[cnt].distance = atof(line);
                        race_fgets(line, MAX_TXTLEN);
@@ -3576,7 +3576,7 @@ void read_topscores(void)
                        race_fgets(line, MAX_TXTLEN);
                        race.records[cnt].avgspeed = atof(line);
                        race_fgets(line, MAX_TXTLEN);
-                       strlcpy(race.records[cnt].date, line, strlen(line));
+                       strlcpy(race.records[cnt].date, line, sizeof(race.records[0].date));
                        race_fgets(line, MAX_TXTLEN);
                        race.records[cnt].weaponmode = atoi(line);
                        race_fgets(line, MAX_TXTLEN);
@VVD VVD added the bug label Jan 1, 2023
@VVD VVD changed the title [BUG] Short title describing issue [BUG] Correction of use strlcpy - potencial security issue Jan 1, 2023
@VVD
Copy link
Author

VVD commented Jan 1, 2023

#define MAX_TXTLEN        128
typedef struct
{
        float time;
        char racername[64];
        char demoname[64];
        float distance;
        float maxspeed;
        float avgspeed;
        float avgcount;
        char date[64];
        raceWeapoMode_t weaponmode;                             // weapon mode
        raceFalseStartMode_t startmode;                 // start mode
        int playernumber;
        int position;
} raceRecord_t;
race_fgets(line, MAX_TXTLEN);
strlcpy(race.records[cnt].racername, line, strlen(line));

If racername > 64 bytes length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant