mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 06:53:34 +08:00
mavlink: fix stack buffer overflow in log handler filepath parsing
- Size LogEntry.filepath to PX4_MAX_FILEPATH instead of hardcoded 60 bytes - Add width specifier to sscanf calls to prevent buffer overflow - Move platform defines from .cpp to .h for reuse - Add static_assert to enforce scanf width < buffer size at compile time Co-authored-by: Cavan O'Horo <cavan.ohoro@gmail.com> Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
co-authored by
Cavan O'Horo
parent
12babb33cb
commit
d7153b7abb
@@ -32,10 +32,24 @@
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <perf/perf_counter.h>
|
||||
#include "mavlink_bridge_header.h"
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
#define PX4LOG_REGULAR_FILE DTYPE_FILE
|
||||
#define PX4LOG_DIRECTORY DTYPE_DIRECTORY
|
||||
#define PX4_MAX_FILEPATH CONFIG_PATH_MAX
|
||||
#define PX4_MAX_FILEPATH_SCANF 255
|
||||
#else
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024 // maximum on macOS
|
||||
#endif
|
||||
#define PX4LOG_REGULAR_FILE DT_REG
|
||||
#define PX4LOG_DIRECTORY DT_DIR
|
||||
#define PX4_MAX_FILEPATH PATH_MAX
|
||||
#define PX4_MAX_FILEPATH_SCANF 1023
|
||||
#endif
|
||||
|
||||
class Mavlink;
|
||||
|
||||
class MavlinkLogHandler
|
||||
@@ -53,7 +67,7 @@ private:
|
||||
uint32_t time_utc{};
|
||||
uint32_t size_bytes{};
|
||||
FILE *fp{nullptr};
|
||||
char filepath[60];
|
||||
char filepath[PX4_MAX_FILEPATH];
|
||||
uint32_t offset{};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user