From 46f977c33929a6bc7e86f72e322ec2b022faddc9 Mon Sep 17 00:00:00 2001 From: John Romein <romein@astron.nl> Date: Fri, 4 Jan 2008 20:07:05 +0000 Subject: [PATCH] bug 225: avoid potential buffer overrun --- Appl/CEP/CS1/CS1_IONProc/src/CS1_ION_main.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Appl/CEP/CS1/CS1_IONProc/src/CS1_ION_main.cc b/Appl/CEP/CS1/CS1_IONProc/src/CS1_ION_main.cc index c43ddca5ec0..f7f54a13b19 100644 --- a/Appl/CEP/CS1/CS1_IONProc/src/CS1_ION_main.cc +++ b/Appl/CEP/CS1/CS1_IONProc/src/CS1_ION_main.cc @@ -36,7 +36,6 @@ #include <fcntl.h> #include <pthread.h> #include <unistd.h> -#include <cstring> extern "C" { #include <lofar.h> @@ -235,18 +234,16 @@ extern "C" void lofar__fini(void); } + inline static void redirect_output() { int fd; - char file_name[32]; - char buffer[17]; + char file_name[64], block_id[17]; - getBGLpersonality()->BlockID(buffer, 16); - - if (memchr(buffer, '\0', 16) == 0) - buffer[16] = '\0'; + getBGLpersonality()->BlockID(block_id, 16); + 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) perror("redirecting stdout/stderr"); -- GitLab