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

ref: convert an sprintf call to snprintf #2866

Merged
merged 17 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Crash when serializing invalid objects (#2858)
- Convert remaining usages of `sprintf` to `snprintf` (#2866)

## 8.4.0

Expand Down
6 changes: 4 additions & 2 deletions Sources/SentryCrash/Recording/SentryCrashReport.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,14 +913,16 @@ writeNotableStackContents(const SentryCrashReportWriter *const writer,
highAddress = tmp;
}
uintptr_t contentsAsPointer;
char nameBuffer[40];
#define SENTRY_NAME_BUFFER_SIZE 40
char nameBuffer[SENTRY_NAME_BUFFER_SIZE];
for (uintptr_t address = lowAddress; address < highAddress; address += sizeof(address)) {
if (sentrycrashmem_copySafely(
(void *)address, &contentsAsPointer, sizeof(contentsAsPointer))) {
sprintf(nameBuffer, "stack@%p", (void *)address);
snprintf(nameBuffer, SENTRY_NAME_BUFFER_SIZE, "stack@%p", (void *)address);
armcknight marked this conversation as resolved.
Show resolved Hide resolved
writeMemoryContentsIfNotable(writer, nameBuffer, contentsAsPointer);
}
}
#undef SENTRY_NAME_BUFFER_SIZE
}

#pragma mark Registers
Expand Down
6 changes: 4 additions & 2 deletions Sources/SentryCrash/Recording/Tools/SentryCrashJSONCodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@ sentrycrashjson_addUIntegerElement(
{
int result = sentrycrashjson_beginElement(context, name);
unlikely_if(result != SentryCrashJSON_OK) { return result; }
char buff[30];
sprintf(buff, "%" PRIu64, value);
#define SENTRY_UINT_BUFFER_SIZE 30
char buff[SENTRY_UINT_BUFFER_SIZE];
snprintf(buff, SENTRY_UINT_BUFFER_SIZE, "%" PRIu64, value);
#undef SENTRY_UINT_BUFFER_SIZE
armcknight marked this conversation as resolved.
Show resolved Hide resolved
return addJSONData(context, buff, (int)strlen(buff));
}

Expand Down