From b43cc55aedddfc8fe1cd119addd18a2f14948b4e Mon Sep 17 00:00:00 2001 From: jusax23 Date: Tue, 28 Nov 2023 21:45:07 +0100 Subject: [PATCH] fixed stdout_read buffer overflow by removing it --- src/stockfish.cpp | 16 +++------------- src/stockfish.h | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/stockfish.cpp b/src/stockfish.cpp index 00eb675..88a38f0 100644 --- a/src/stockfish.cpp +++ b/src/stockfish.cpp @@ -12,11 +12,8 @@ #include #endif -#define BUFFER_SIZE 1024 - -#include "stockfish.h" - #include "fixes.h" +#include "stockfish.h" const char *QUITOK = "quitok\n"; @@ -54,17 +51,10 @@ ssize_t stockfish_stdin_write(char *data) { } std::string data; -char buffer[BUFFER_SIZE + 1]; -char* stockfish_stdout_read() { +const char *stockfish_stdout_read() { if (getline(fakeout, data)) { - size_t len = data.length(); - size_t i; - for (i = 0; i < len && i < BUFFER_SIZE; i++) { - buffer[i] = data[i]; - } - buffer[i] = 0; - return buffer; + return data.c_str(); } return nullptr; } \ No newline at end of file diff --git a/src/stockfish.h b/src/stockfish.h index c950bcf..b7fa36f 100644 --- a/src/stockfish.h +++ b/src/stockfish.h @@ -45,4 +45,4 @@ FFI_PLUGIN_EXPORT ssize_t stockfish_stdin_write(char *data); #ifndef _ffigen extern "C" #endif -FFI_PLUGIN_EXPORT char * stockfish_stdout_read(); \ No newline at end of file +FFI_PLUGIN_EXPORT const char * stockfish_stdout_read(); \ No newline at end of file