⛏️ index : buildtools.git

author Adrien Destugues <pulkomandy@gmail.com> 2017-07-16 19:40:50.0 +02:00:00
committer Adrien Destugues <pulkomandy@gmail.com> 2017-07-16 19:40:50.0 +02:00:00
commit
259af3cf06a9e75cc93903d6ff4d8cad89f94874 [patch]
tree
3cef5b661ee68877340c06299b365da9963f0124
parent
560f4f562f2eaf6ad27a30880f027a6ca4bdb4a6
download
259af3cf06a9e75cc93903d6ff4d8cad89f94874.tar.gz

Increase MAXSYM and add sanity checks.

I had jam crash in strange ways because a stack-allocatted aray was
overflowing. Double the limit, and add sanity checks with exit and clear
error messages in case it happens again.

Diff

 jam/builtins.c | 28 +++++++++++++++++++++-------
 jam/expand.c   |  8 ++++++++
 jam/headers.c  |  4 ++++
 jam/jam.h      |  2 +-
 jam/variable.c |  4 ++++
 5 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/jam/builtins.c b/jam/builtins.c
index a1b317c..4a8a477 100644
--- a/jam/builtins.c
+++ a/jam/builtins.c
@@ -276,19 +276,19 @@
	LOL	*args,
	int	*jmp )
{
	LIST *l, *r;
	LIST *result = 0;
    LIST *l, *r;
    LIST *result = 0;

	/* For each pattern */
    /* For each pattern */

	for( l = lol_get( args, 0 ); l; l = l->next )
	{
	    regexp *re = regcomp( l->string );
    for( l = lol_get( args, 0 ); l; l = l->next )
    {
	regexp *re = regcomp( l->string );

	    /* For each string to match against */
	/* For each string to match against */

	    for( r = lol_get( args, 1 ); r; r = r->next )
		if( regexec( re, r->string ) )
	for( r = lol_get( args, 1 ); r; r = r->next )
	    if( regexec( re, r->string ) )
	    {
		int i, top;

@@ -305,14 +305,18 @@
		{
		    char buf[ MAXSYM ];
		    int l = re->endp[i] - re->startp[i];
		    if (l > MAXSYM) {
			printf("MAXSYM is too low! NEed at least %d\n", l);
			exit(-1);
		    }
		    memcpy( buf, re->startp[i], l );
		    buf[ l ] = 0;
		    result = list_new( result, buf, 0 );
		}
	    }

	    free( (char *)re );
	}
	free( (char *)re );
    }

	return result;
    return result;
}
diff --git a/jam/expand.c b/jam/expand.c
index aca9137..faadf13 100644
--- a/jam/expand.c
+++ a/jam/expand.c
@@ -206,6 +206,10 @@
		/* Look for a : modifier in the variable name */
		/* Must copy into varname so we can modify it */

		if (strlen(vars->string) > MAXSYM) {
		    printf("MAXSYM is too low! Need at least %d\n", l);
		    exit(-1);
		}
		strcpy( varname, vars->string );

		if( colon = strchr( varname, MAGIC_COLON ) )
@@ -274,6 +278,10 @@
		    LIST *rem;
		    char *out1;

		    if (out - out_buf > MAXSYM) {
			printf("MAXSYM is too low!\n");
			exit(-1);
		    }
		    /* Handle end subscript (length actually) */

		    if( sub2 >= 0 && --sub2 < 0 )
diff --git a/jam/headers.c b/jam/headers.c
index 197d32e..7f5ccb7 100644
--- a/jam/headers.c
+++ a/jam/headers.c
@@ -129,6 +129,10 @@

		char buf2[ MAXSYM ];
		int l = re[i]->endp[1] - re[i]->startp[1];
		if (l > MAXSYM) {
			printf("MAXSYM is too low! Need at least %d\n", l);
			exit(-1);
		}
		memcpy( buf2, re[i]->startp[1], l );
		buf2[ l ] = 0;
		result = list_new( result, buf2, 0 );
diff --git a/jam/jam.h b/jam/jam.h
index 6ce522a..da3db48 100644
--- a/jam/jam.h
+++ a/jam/jam.h
@@ -478,7 +478,7 @@

/* You probably don't need to muck with these. */

# define MAXSYM	1024	/* longest symbol in the environment */
# define MAXSYM	2048	/* longest symbol in the environment */
# define MAXJPATH 1024	/* longest filename */

# define MAXJOBS 64	/* silently enforce -j limit */
diff --git a/jam/variable.c b/jam/variable.c
index 0a2d07c..97b7bb0 100644
--- a/jam/variable.c
+++ a/jam/variable.c
@@ -117,6 +117,10 @@

		/* Get name */

		if (val - *e > MAXSYM) {
			printf("MAXSYM is too low, need at least %d\n", val - *e);
			exit(-1);
		}
		strncpy( buf, *e, val - *e );
		buf[ val - *e ] = '\0';