From 205f98568eef0daa98706bd9cbff849df6902ee2 Mon Sep 17 00:00:00 2001 From: "Henrique F. Simoes" Date: Mon, 30 Oct 2023 14:10:03 -0300 Subject: [PATCH] base: apply StreamBuffer::grow patch to StreamDevice. This patch is applied with git-apply(1) so that the Git history is not required to exist. This fix should be removed once it is accepted in upstream. A directory for patches has been created so that they aren't scattered across the installation scripts' directory. --- base/Dockerfile | 4 +++- base/install_modules.sh | 4 +++- base/{ => patches}/nanohttp_stream.patch | 0 base/patches/streambuffer-grow.patch | 27 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) rename base/{ => patches}/nanohttp_stream.patch (100%) create mode 100644 base/patches/streambuffer-grow.patch diff --git a/base/Dockerfile b/base/Dockerfile index 66740b9..4fd8d02 100644 --- a/base/Dockerfile +++ b/base/Dockerfile @@ -42,10 +42,12 @@ ARG AREA_DETECTOR_VERSION ARG MOTOR_VERSION WORKDIR ${EPICS_MODULES_PATH} + +COPY patches/streambuffer-grow.patch . COPY install_modules.sh . RUN ./install_modules.sh -COPY nanohttp_stream.patch . +COPY patches/nanohttp_stream.patch . COPY install_area_detector.sh . RUN ./install_area_detector.sh diff --git a/base/install_modules.sh b/base/install_modules.sh index 76ef731..75979ec 100755 --- a/base/install_modules.sh +++ b/base/install_modules.sh @@ -62,7 +62,9 @@ EPICS_BASE = ${EPICS_BASE_PATH} CALC = ${EPICS_MODULES_PATH}/calc " -install_github_module paulscherrerinstitute StreamDevice STREAM $STREAMDEVICE_VERSION " +download_github_module paulscherrerinstitute StreamDevice $STREAMDEVICE_VERSION +git apply --directory StreamDevice ${EPICS_MODULES_PATH}/streambuffer-grow.patch +install_module StreamDevice STREAM " EPICS_BASE = ${EPICS_BASE_PATH} ASYN = ${EPICS_MODULES_PATH}/asyn diff --git a/base/nanohttp_stream.patch b/base/patches/nanohttp_stream.patch similarity index 100% rename from base/nanohttp_stream.patch rename to base/patches/nanohttp_stream.patch diff --git a/base/patches/streambuffer-grow.patch b/base/patches/streambuffer-grow.patch new file mode 100644 index 0000000..79d85e0 --- /dev/null +++ b/base/patches/streambuffer-grow.patch @@ -0,0 +1,27 @@ +From https://github.com/paulscherrerinstitute/StreamDevice/pull/96 +From 34cf0476915ac7b6770af88ab02f836b6ffb710d Mon Sep 17 00:00:00 2001 +From: sudastelaro +Date: Fri, 27 Oct 2023 12:54:27 -0300 +Subject: [PATCH] Clear the right number of bytes in StreamBuffer + +The wrong number of bytes was being cleared in StreamBuffer::grow. That +could lead to memory access out of bounds. +--- + src/StreamBuffer.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/StreamBuffer.cc b/src/StreamBuffer.cc +index fdba24f..c7d53b4 100644 +--- a/src/StreamBuffer.cc ++++ b/src/StreamBuffer.cc +@@ -144,7 +144,7 @@ grow(size_t minsize) + // just move contents to start of buffer and clear end + // to avoid reallocation + memmove(buffer, buffer+offs, len); +- memset(buffer+len, 0, offs); ++ memset(buffer+len, 0, cap-len); + offs = 0; + return; + } +-- +2.34.1