Commit 3f88bae2 authored by Federico Vaga's avatar Federico Vaga

sw:lib: fix path[] allocation

BUG reported on gcc-9, the buffer path[] may not be enough to contain the
string that we want to generate from sprintf().
This patch allocates properly the buffer
Reported-by: Dimitris Lampridis's avatarDimitris Lampridis <dimitris.lampridis@cern.ch>
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 4ae03dfa
......@@ -520,12 +520,12 @@ int trtl_cpu_load_application_raw(struct trtl_dev *trtl,
unsigned int offset)
{
struct trtl_desc *wdesc = (struct trtl_desc *)trtl;
char path[TRTL_PATH_LEN];
char path[TRTL_PATH_LEN + TRTL_NAME_LEN + 1 + 3];
int fd;
ssize_t ret;
size_t i = 0;
snprintf(path, TRTL_PATH_LEN, "%s/%s-%02u",
snprintf(path, sizeof(path), "%s/%s-%02u",
wdesc->path, wdesc->name, index);
fd = open(path, O_WRONLY);
if (fd < 0)
......@@ -565,10 +565,10 @@ int trtl_cpu_dump_application_raw(struct trtl_dev *trtl,
unsigned int offset)
{
struct trtl_desc *wdesc = (struct trtl_desc *)trtl;
char path[TRTL_PATH_LEN];
char path[TRTL_PATH_LEN + TRTL_NAME_LEN + 1 + 3];
int fd, i = 0, c = 100;
snprintf(path, TRTL_PATH_LEN, "%s/%s-%02u",
snprintf(path, sizeof(path), "%s/%s-%02u",
wdesc->path, wdesc->name, index);
fd = open(path, O_RDONLY);
if (fd < 0)
......@@ -683,12 +683,13 @@ int trtl_cpu_dump_application_file(struct trtl_dev *trtl,
static int trtl_dev_open(struct trtl_desc *wdesc)
{
if (wdesc->fd_dev < 0) {
char path[64];
char path[TRTL_PATH_LEN + TRTL_NAME_LEN + 1];
snprintf(path, sizeof(path), "%s/%s", wdesc->path, wdesc->name);
wdesc->fd_dev = open(path, O_RDWR);
if (wdesc->fd_dev < 0)
return -1;
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment