mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-02 14:51:37 +08:00
Prevent stack overflow when flashing px4io
Large local variable causing stack overflow when attempting to flash IO!!!
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -413,11 +414,17 @@ static int read_with_retry(int fd, void *buf, size_t n)
|
|||||||
int
|
int
|
||||||
PX4IO_Uploader::program(size_t fw_size)
|
PX4IO_Uploader::program(size_t fw_size)
|
||||||
{
|
{
|
||||||
uint8_t file_buf[PROG_MULTI_MAX];
|
uint8_t *file_buf;
|
||||||
ssize_t count;
|
ssize_t count;
|
||||||
int ret;
|
int ret;
|
||||||
size_t sent = 0;
|
size_t sent = 0;
|
||||||
|
|
||||||
|
file_buf = (uint8_t *)malloc(PROG_MULTI_MAX);
|
||||||
|
if (!file_buf) {
|
||||||
|
log("Can't allocate program buffer");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
log("programming %u bytes...", (unsigned)fw_size);
|
log("programming %u bytes...", (unsigned)fw_size);
|
||||||
|
|
||||||
ret = lseek(_fw_fd, 0, SEEK_SET);
|
ret = lseek(_fw_fd, 0, SEEK_SET);
|
||||||
@@ -438,8 +445,10 @@ PX4IO_Uploader::program(size_t fw_size)
|
|||||||
(int)errno);
|
(int)errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0) {
|
||||||
|
free(file_buf);
|
||||||
return OK;
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
sent += count;
|
sent += count;
|
||||||
|
|
||||||
@@ -455,9 +464,12 @@ PX4IO_Uploader::program(size_t fw_size)
|
|||||||
|
|
||||||
ret = get_sync(1000);
|
ret = get_sync(1000);
|
||||||
|
|
||||||
if (ret != OK)
|
if (ret != OK) {
|
||||||
|
free(file_buf);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
free(file_buf);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user