REVIEWED: Security: strncpy() replaced by snprintf()

This commit is contained in:
Ray
2026-07-06 19:13:44 +02:00
parent 65abee1cba
commit 5992929e56
12 changed files with 107 additions and 106 deletions

View File

@@ -2331,7 +2331,7 @@ static rlExampleInfo *LoadExampleInfo(const char *exFileName)
// Example found in collection
exInfo = (rlExampleInfo *)RL_CALLOC(1, sizeof(rlExampleInfo));
strncpy(exInfo->name, GetFileNameWithoutExt(exFileName), 128 - 1);
snprintf(exInfo->name, 128, "%s", GetFileNameWithoutExt(exFileName));
strncpy(exInfo->category, exInfo->name, TextFindIndex(exInfo->name, "_"));
char *exText = LoadFileText(exFileName);
@@ -2377,7 +2377,7 @@ static rlExampleInfo *LoadExampleInfo(const char *exFileName)
int copyrightIndex = TextFindIndex(exText, "Copyright (c) ");
int yearStartIndex = copyrightIndex + 14;
char yearText[5] = { 0 };
strncpy(yearText, exText + yearStartIndex, 4);
snprintf(yearText, 5, "%s", exText + yearStartIndex);
exInfo->yearCreated = TextToInteger(yearText);
// Check for review year included (or just use creation year)
if (exText[yearStartIndex + 4] == '-') strncpy(yearText, exText + yearStartIndex + 5, 4);
@@ -2425,7 +2425,7 @@ static int ParseExampleInfoLine(const char *line, rlExampleInfo *entry)
#define MAX_EXAMPLE_INFO_LINE_LEN 512
char temp[MAX_EXAMPLE_INFO_LINE_LEN] = { 0 };
strncpy(temp, line, MAX_EXAMPLE_INFO_LINE_LEN);
snprintf(temp, MAX_EXAMPLE_INFO_LINE_LEN, "%s", line);
temp[MAX_EXAMPLE_INFO_LINE_LEN - 1] = '\0'; // Ensure null termination
int tokenCount = 0;
@@ -2902,7 +2902,7 @@ static void UpdateWebMetadata(const char *exHtmlPath, const char *exFilePath)
char exTitle[64] = { 0 }; // Example title: fileName without extension, replacing underscores by spaces
// Get example name: replace underscore by spaces
strncpy(exName, GetFileNameWithoutExt(exHtmlPathCopy), 64 - 1);
snprintf(exName, 64, "%s", GetFileNameWithoutExt(exHtmlPathCopy));
strcpy(exTitle, exName);
for (int i = 0; (i < 64) && (exTitle[i] != '\0'); i++) { if (exTitle[i] == '_') exTitle[i] = ' '; }