Skip to content
Snippets Groups Projects
Commit 46f977c3 authored by John Romein's avatar John Romein
Browse files

bug 225:

avoid potential buffer overrun
parent dc20fb1b
Branches
Tags
No related merge requests found
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <cstring>
extern "C" { extern "C" {
#include <lofar.h> #include <lofar.h>
...@@ -235,18 +234,16 @@ extern "C" ...@@ -235,18 +234,16 @@ extern "C"
void lofar__fini(void); void lofar__fini(void);
} }
inline static void redirect_output() inline static void redirect_output()
{ {
int fd; int fd;
char file_name[32]; char file_name[64], block_id[17];
char buffer[17];
getBGLpersonality()->BlockID(buffer, 16);
if (memchr(buffer, '\0', 16) == 0) getBGLpersonality()->BlockID(block_id, 16);
buffer[16] = '\0'; block_id[16] = '\0'; // just in case it was not already '\0' terminated
sprintf(file_name, "run.CS1_IONProc.%s.%u", buffer, getBGLpersonality()->getPsetNum()); sprintf(file_name, "run.CS1_IONProc.%s.%u", block_id, getBGLpersonality()->getPsetNum());
if ((fd = open(file_name, O_CREAT | O_TRUNC | O_RDWR, 0666)) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0) if ((fd = open(file_name, O_CREAT | O_TRUNC | O_RDWR, 0666)) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0)
perror("redirecting stdout/stderr"); perror("redirecting stdout/stderr");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment