Fix static buffer overflow in genname( ) in LLgen
This should fix at least some instances of the "undefined reference to `LLnc_recover'" error that happens in some builds (https://github.com/davidgiven/ack/issues/218). The bug was that genname( ) used a static `namebuf' buffer and did not properly check for overflow when writing into it. The result was that the `non_corr' variable was sometimes overwritten with a non-zero value when it should be zero, causing bogus results later. This proposed patch makes genname( ) dynamically allocate and resize a buffer for holding a target file name. I also take this chance to fix a typo in correct_prefix().
This commit is contained in:
		
							parent
							
								
									7c51d86c4e
								
							
						
					
					
						commit
						9c7ce04cec
					
				
					 1 changed files with 7 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -1366,15 +1366,15 @@ STATIC void gencases(int *tokenlist, int caseno, int compacted)
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static char namebuf[20];
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Generate a target file name from the
 | 
			
		||||
 * source file name s.
 | 
			
		||||
 */STATIC string genname(string s)
 | 
			
		||||
 */
 | 
			
		||||
STATIC string genname(string s)
 | 
			
		||||
{
 | 
			
		||||
	register string c, d;
 | 
			
		||||
	register string namebuf, c, d;
 | 
			
		||||
 | 
			
		||||
	namebuf = alloc(strlen(s) + 3);
 | 
			
		||||
	c = namebuf;
 | 
			
		||||
	while (*s)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -1394,14 +1394,10 @@ static char namebuf[20];
 | 
			
		|||
			break;
 | 
			
		||||
	if (d == namebuf)
 | 
			
		||||
		d = c;
 | 
			
		||||
	if (d >= &namebuf[12])
 | 
			
		||||
	{
 | 
			
		||||
		fatal(0, "%s : filename too long", namebuf);
 | 
			
		||||
	}
 | 
			
		||||
	*d++ = '.';
 | 
			
		||||
	*d++ = 'c';
 | 
			
		||||
	*d = '\0';
 | 
			
		||||
	return namebuf;
 | 
			
		||||
	*d++ = '\0';
 | 
			
		||||
	return ralloc(namebuf, d - namebuf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
STATIC void genpush(int d)
 | 
			
		||||
| 
						 | 
				
			
			@ -1509,7 +1505,7 @@ STATIC void correct_prefix(void)
 | 
			
		|||
		fprintf(f, "#define LLoldlevel %soldlevel\n", s);
 | 
			
		||||
		fprintf(f, "#define LLmessage %smessage\n", s);
 | 
			
		||||
#ifdef NON_CORRECTING
 | 
			
		||||
		fprintf(f, "#define LLnc_recovery %sncrecovery\n", s);
 | 
			
		||||
		fprintf(f, "#define LLnc_recover %sncrecover\n", s);
 | 
			
		||||
		fprintf(f, "#define LLstartsymb %sstartsymb\n", s);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue