mirror of
https://review.haiku-os.org/buildtools
synced 2024-11-23 07:18:49 +01:00
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.
This commit is contained in:
parent
560f4f562f
commit
259af3cf06
@ -276,19 +276,19 @@ builtin_match(
|
|||||||
LOL *args,
|
LOL *args,
|
||||||
int *jmp )
|
int *jmp )
|
||||||
{
|
{
|
||||||
LIST *l, *r;
|
LIST *l, *r;
|
||||||
LIST *result = 0;
|
LIST *result = 0;
|
||||||
|
|
||||||
/* For each pattern */
|
/* For each pattern */
|
||||||
|
|
||||||
for( l = lol_get( args, 0 ); l; l = l->next )
|
for( l = lol_get( args, 0 ); l; l = l->next )
|
||||||
{
|
{
|
||||||
regexp *re = regcomp( l->string );
|
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 )
|
for( r = lol_get( args, 1 ); r; r = r->next )
|
||||||
if( regexec( re, r->string ) )
|
if( regexec( re, r->string ) )
|
||||||
{
|
{
|
||||||
int i, top;
|
int i, top;
|
||||||
|
|
||||||
@ -305,14 +305,18 @@ builtin_match(
|
|||||||
{
|
{
|
||||||
char buf[ MAXSYM ];
|
char buf[ MAXSYM ];
|
||||||
int l = re->endp[i] - re->startp[i];
|
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 );
|
memcpy( buf, re->startp[i], l );
|
||||||
buf[ l ] = 0;
|
buf[ l ] = 0;
|
||||||
result = list_new( result, buf, 0 );
|
result = list_new( result, buf, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free( (char *)re );
|
free( (char *)re );
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,10 @@ var_expand(
|
|||||||
/* Look for a : modifier in the variable name */
|
/* Look for a : modifier in the variable name */
|
||||||
/* Must copy into varname so we can modify it */
|
/* 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 );
|
strcpy( varname, vars->string );
|
||||||
|
|
||||||
if( colon = strchr( varname, MAGIC_COLON ) )
|
if( colon = strchr( varname, MAGIC_COLON ) )
|
||||||
@ -274,6 +278,10 @@ var_expand(
|
|||||||
LIST *rem;
|
LIST *rem;
|
||||||
char *out1;
|
char *out1;
|
||||||
|
|
||||||
|
if (out - out_buf > MAXSYM) {
|
||||||
|
printf("MAXSYM is too low!\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
/* Handle end subscript (length actually) */
|
/* Handle end subscript (length actually) */
|
||||||
|
|
||||||
if( sub2 >= 0 && --sub2 < 0 )
|
if( sub2 >= 0 && --sub2 < 0 )
|
||||||
|
@ -129,6 +129,10 @@ headers1(
|
|||||||
|
|
||||||
char buf2[ MAXSYM ];
|
char buf2[ MAXSYM ];
|
||||||
int l = re[i]->endp[1] - re[i]->startp[1];
|
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 );
|
memcpy( buf2, re[i]->startp[1], l );
|
||||||
buf2[ l ] = 0;
|
buf2[ l ] = 0;
|
||||||
result = list_new( result, buf2, 0 );
|
result = list_new( result, buf2, 0 );
|
||||||
|
@ -478,7 +478,7 @@
|
|||||||
|
|
||||||
/* You probably don't need to muck with these. */
|
/* 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 MAXJPATH 1024 /* longest filename */
|
||||||
|
|
||||||
# define MAXJOBS 64 /* silently enforce -j limit */
|
# define MAXJOBS 64 /* silently enforce -j limit */
|
||||||
|
@ -117,6 +117,10 @@ var_defines( const char **e )
|
|||||||
|
|
||||||
/* Get name */
|
/* 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 );
|
strncpy( buf, *e, val - *e );
|
||||||
buf[ val - *e ] = '\0';
|
buf[ val - *e ] = '\0';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user