浏览代码

Merge pull request #4833 from MykBamberg/master

[rcore] Use snprintf to prevent buffer overflow in path construction
pull/4839/head
Ray 1 个月前
committed by GitHub
父节点
当前提交
654d5c80c2
找不到此签名对应的密钥 GPG 密钥 ID: B5690EEEBB952194
共有 1 个文件被更改,包括 14 次插入6 次删除
  1. +14
    -6
      src/rcore.c

+ 14
- 6
src/rcore.c 查看文件

@ -3688,12 +3688,16 @@ static void ScanDirectoryFiles(const char *basePath, FilePathList *files, const
(strcmp(dp->d_name, "..") != 0)) (strcmp(dp->d_name, "..") != 0))
{ {
#if defined(_WIN32) #if defined(_WIN32)
sprintf(path, "%s\\%s", basePath, dp->d_name);
kt">int realPathLengthspan> = snprintf(path, sizeof(path) - 1, "%s\\%s", basePath, dp->d_name);
#else #else
sprintf(path, "%s/%s", basePath, dp->d_name);
kt">int realPathLengthspan> = snprintf(path, sizeof(path) - 1, "%s/%s", basePath, dp->d_name);
#endif #endif
if (filter != NULL)
if (realPathLength < 0 || realPathLength >= sizeof(path))
{
TRACELOG(LOG_WARNING, "FILEIO: Path longer than %d characters (%s...)", MAX_FILEPATH_LENGTH, basePath);
}
else if (filter != NULL)
{ {
if (IsPathFile(path)) if (IsPathFile(path))
{ {
@ -3742,12 +3746,16 @@ static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *fi
{ {
// Construct new path from our base path // Construct new path from our base path
#if defined(_WIN32) #if defined(_WIN32)
sprintf(path, "%s\\%s", basePath, dp->d_name);
kt">int realPathLengthspan> = snprintf(path, sizeof(path) - 1, "%s\\%s", basePath, dp->d_name);
#else #else
sprintf(path, "%s/%s", basePath, dp->d_name);
kt">int realPathLengthspan> = snprintf(path, sizeof(path) - 1, "%s/%s", basePath, dp->d_name);
#endif #endif
if (IsPathFile(path))
if (realPathLength < 0 || realPathLength >= sizeof(path))
{
TRACELOG(LOG_WARNING, "FILEIO: Path longer than %d characters (%s...)", MAX_FILEPATH_LENGTH, basePath);
}
else if (IsPathFile(path))
{ {
if (filter != NULL) if (filter != NULL)
{ {

正在加载...
取消
保存