From cba1ddff4ae6ad51f9b1445a69e5f93dc69196f1 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Fri, 15 Sep 2017 15:43:42 +0200 Subject: [PATCH] ncl: Fix buffer overflow in ymake-filter (#5357) Fixes a problem in ymake-filter: The line buffer is currently hardcoded to be 2048 bytes large but some Makefiles contain lines longer than that. This caused the Makefiles to sometimes not be generated, consequently failing parts of the build. --- .../repos/builtin/packages/ncl/package.py | 2 ++ .../builtin/packages/ncl/ymake-filter.patch | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 var/spack/repos/builtin/packages/ncl/ymake-filter.patch diff --git a/var/spack/repos/builtin/packages/ncl/package.py b/var/spack/repos/builtin/packages/ncl/package.py index 49ebbc8f47..1d338bcd9c 100644 --- a/var/spack/repos/builtin/packages/ncl/package.py +++ b/var/spack/repos/builtin/packages/ncl/package.py @@ -43,6 +43,8 @@ class Ncl(Package): patch('spack_ncl.patch') # Make ncl compile with hdf5 1.10 patch('hdf5.patch') + # ymake-filter's buffer may overflow + patch('ymake-filter.patch') # This installation script is implemented according to this manual: # http://www.ncl.ucar.edu/Download/build_from_src.shtml diff --git a/var/spack/repos/builtin/packages/ncl/ymake-filter.patch b/var/spack/repos/builtin/packages/ncl/ymake-filter.patch new file mode 100644 index 0000000000..915e82035f --- /dev/null +++ b/var/spack/repos/builtin/packages/ncl/ymake-filter.patch @@ -0,0 +1,33 @@ +--- ncl_ncarg-6.4.0/config/ymake-filter.c.orig 2017-02-23 20:11:55.000000000 +0100 ++++ ncl_ncarg-6.4.0/config/ymake-filter.c 2017-09-13 14:52:34.800989229 +0200 +@@ -150,13 +150,29 @@ + getcppline() + { + int c; +- static char buf[2048]; ++ static int s = 2048; ++ static char *buf = NULL; + char *p; + ++ if (buf == NULL) ++ { ++ buf = malloc(s); ++ } ++ + p = buf; + + do + { ++ if (p >= buf + s) ++ { ++ char* old = buf; ++ ++ /* Need to increase the size of buf. */ ++ s += 1024; ++ buf = realloc(buf, s); ++ p = buf + (p - old); ++ } ++ + switch(c = getchar()) + { + /*