Skip to content

Commit

Permalink
Fix code scanning alert no. 6: Time-of-check time-of-use filesystem r…
Browse files Browse the repository at this point in the history
…ace condition

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
brustolin and github-advanced-security[bot] authored Oct 24, 2024
1 parent 4569cc9 commit ce2a831
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,18 @@ sentrycrashfu_readEntireFile(const char *const path, char **data, int *length, i
int bytesToRead = maxLength;

struct stat st;
if (stat(path, &st) < 0) {
SENTRY_ASYNC_SAFE_LOG_ERROR("Could not stat %s: %s", path, strerror(errno));
goto done;
}

fd = open(path, O_RDONLY);
if (fd < 0) {
SENTRY_ASYNC_SAFE_LOG_ERROR("Could not open %s: %s", path, strerror(errno));
goto done;
}

if (fstat(fd, &st) < 0) {
SENTRY_ASYNC_SAFE_LOG_ERROR("Could not fstat %s: %s", path, strerror(errno));
goto done;
}

if (bytesToRead == 0 || bytesToRead >= (int)st.st_size) {
bytesToRead = (int)st.st_size;
} else if (bytesToRead > 0) {
Expand Down

0 comments on commit ce2a831

Please sign in to comment.