Skip to content

Commit f5a9f3f

Browse files
authored
Fix: Use strlcpy to save session replay info path (#4740)
Use safer strlcpy and add room for null-terminator when saving sr path for info file.
1 parent 5bcc0d8 commit f5a9f3f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixed
6+
7+
- Use strlcpy to save session replay info path (#4740)
8+
39
## 8.44.0-beta.1
410

511
### Fixes

Sources/Sentry/SentrySessionReplaySyncC.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ sentrySessionReplaySync_start(const char *const path)
2121
free(crashReplay.path);
2222
}
2323

24-
crashReplay.path = malloc(strlen(path));
25-
strcpy(crashReplay.path, path);
24+
size_t buffer_size = sizeof(char) * (strlen(path) + 1); // Add a byte for the null-terminator.
25+
crashReplay.path = malloc(buffer_size);
26+
if (crashReplay.path) {
27+
strlcpy(crashReplay.path, path, buffer_size);
28+
} else {
29+
crashReplay.path = NULL;
30+
SENTRY_ASYNC_SAFE_LOG_ERROR(
31+
"Could not copy the path to save session replay in case of an error. File path: %s",
32+
path);
33+
}
2634
}
2735

2836
void
@@ -35,6 +43,11 @@ sentrySessionReplaySync_updateInfo(unsigned int segmentId, double lastSegmentEnd
3543
void
3644
sentrySessionReplaySync_writeInfo(void)
3745
{
46+
if (crashReplay.path == NULL) {
47+
SENTRY_ASYNC_SAFE_LOG_ERROR("There is no path to write replay information");
48+
return;
49+
}
50+
3851
int fd = open(crashReplay.path, O_RDWR | O_CREAT | O_TRUNC, 0644);
3952

4053
if (fd < 1) {

0 commit comments

Comments
 (0)