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.
This commit is contained in:
Michael Kuhn 2017-09-15 15:43:42 +02:00 committed by Adam J. Stewart
parent abc0c65d03
commit cba1ddff4a
2 changed files with 35 additions and 0 deletions

View file

@ -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

View file

@ -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())
{
/*