mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 11:29:58 +03:00
fix format overflow in blackboxVirtualBeginLog (#14373)
* cast largestLogFileNumber to 16bits to prevent format overflow * Update src/main/blackbox/blackbox_virtual.c remove uint16 cast Co-authored-by: Petr Ledvina <ledvinap@gmail.com> * Update src/main/blackbox/blackbox_virtual.c use snprintf instead of strlen Co-authored-by: Petr Ledvina <ledvinap@gmail.com> --------- Co-authored-by: Petr Ledvina <ledvinap@gmail.com>
This commit is contained in:
parent
32a7fbef5d
commit
37c921cdf0
2 changed files with 4 additions and 4 deletions
|
@ -87,9 +87,9 @@ bool blackboxVirtualBeginLog(void)
|
||||||
if (blackboxVirtualFile != NULL) {
|
if (blackboxVirtualFile != NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const size_t name_buffer_length = strlen(LOGFILE_PREFIX) + 5 + strlen(LOGFILE_SUFFIX) + 2; //file name template: LOG00001.BFL
|
const size_t name_buffer_length = snprintf(NULL, 0, "%s%05u.%s", LOGFILE_PREFIX, (largestLogFileNumber + 1) % 100000, LOGFILE_SUFFIX);
|
||||||
char filename[name_buffer_length];
|
char filename[name_buffer_length];
|
||||||
sprintf(filename, "%s%05i.%s", LOGFILE_PREFIX, largestLogFileNumber + 1, LOGFILE_SUFFIX);
|
snprintf(filename, sizeof(filename), "%s%05u.%s", LOGFILE_PREFIX, (largestLogFileNumber + 1) % 100000, LOGFILE_SUFFIX);
|
||||||
blackboxVirtualFile = fopen(filename, "w");
|
blackboxVirtualFile = fopen(filename, "w");
|
||||||
if (blackboxVirtualFile != NULL) {
|
if (blackboxVirtualFile != NULL) {
|
||||||
largestLogFileNumber++;
|
largestLogFileNumber++;
|
||||||
|
@ -111,7 +111,7 @@ void blackboxVirtualClose(void)
|
||||||
blackboxVirtualEndLog();
|
blackboxVirtualEndLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t blackboxVirtualLogFileNumber(void)
|
int32_t blackboxVirtualLogFileNumber(void)
|
||||||
{
|
{
|
||||||
return largestLogFileNumber;
|
return largestLogFileNumber;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,4 +32,4 @@ bool blackboxVirtualFlush(void);
|
||||||
bool blackboxVirtualBeginLog(void);
|
bool blackboxVirtualBeginLog(void);
|
||||||
bool blackboxVirtualEndLog(void);
|
bool blackboxVirtualEndLog(void);
|
||||||
void blackboxVirtualClose(void);
|
void blackboxVirtualClose(void);
|
||||||
uint32_t blackboxVirtualLogFileNumber(void);
|
int32_t blackboxVirtualLogFileNumber(void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue