Fix buffer overflow issue.
This commit is contained in:
		
							parent
							
								
									dcc2be5e8c
								
							
						
					
					
						commit
						a6120c220e
					
				
					 4 changed files with 26 additions and 11 deletions
				
			
		|  | @ -15,7 +15,7 @@ | ||||||
| #include	"comm0.h" | #include	"comm0.h" | ||||||
| #include	"comm1.h" | #include	"comm1.h" | ||||||
| #include	"y.tab.h" | #include	"y.tab.h" | ||||||
| #include	<object.h> | #include	"object.h" | ||||||
| 
 | 
 | ||||||
| extern YYSTYPE	yylval; | extern YYSTYPE	yylval; | ||||||
| 
 | 
 | ||||||
|  | @ -243,7 +243,8 @@ archive(void) { | ||||||
| 		if (needed()) { | 		if (needed()) { | ||||||
| 			fseek(input,offset,0); | 			fseek(input,offset,0); | ||||||
| 			archsize = header.ar_size; | 			archsize = header.ar_size; | ||||||
| 			header.ar_name[14] = '\0'; | 			// TODO: To check if this is correct.
 | ||||||
|  | 			header.ar_name[AR_NAME_MAX-1] = '\0'; | ||||||
| 			parse(remember(header.ar_name)); | 			parse(remember(header.ar_name)); | ||||||
| 		} | 		} | ||||||
| 		offset += header.ar_size; | 		offset += header.ar_size; | ||||||
|  | @ -330,7 +331,7 @@ parse(char *s) | ||||||
| 	 */ | 	 */ | ||||||
| #ifdef ASLD | #ifdef ASLD | ||||||
| 	for (i = 0; i < H_SIZE; i++) { | 	for (i = 0; i < H_SIZE; i++) { | ||||||
| 		while (ip = hashtab[H_LOCAL+i]) { | 		while ((ip = hashtab[H_LOCAL+i])) { | ||||||
| 			/*
 | 			/*
 | ||||||
| 			 * cleanup local queue | 			 * cleanup local queue | ||||||
| 			 */ | 			 */ | ||||||
|  |  | ||||||
|  | @ -439,7 +439,7 @@ static int innumber(int c) | ||||||
| 	if (radix != 16 && (c == 'f' || c == 'b')) | 	if (radix != 16 && (c == 'f' || c == 'b')) | ||||||
| 		return (infbsym(num)); | 		return (infbsym(num)); | ||||||
| 	yylval.y_valu = 0; | 	yylval.y_valu = 0; | ||||||
| 	while (c = *p++) | 	while ((c = *p++)) | ||||||
| 	{ | 	{ | ||||||
| 		if (c > '9') | 		if (c > '9') | ||||||
| 			c -= ('a' - '9' - 1); | 			c -= ('a' - '9' - 1); | ||||||
|  | @ -593,7 +593,7 @@ int hash(const char* p) | ||||||
| 	int c; | 	int c; | ||||||
| 
 | 
 | ||||||
| 	h = 0; | 	h = 0; | ||||||
| 	while (c = *p++) | 	while ((c = *p++)) | ||||||
| 	{ | 	{ | ||||||
| 		h <<= 2; | 		h <<= 2; | ||||||
| 		h += c; | 		h += c; | ||||||
|  | @ -668,10 +668,16 @@ item_t* fb_shift(int lab) | ||||||
| 
 | 
 | ||||||
| 	ip = fb_ptr[FB_FORW + lab]; | 	ip = fb_ptr[FB_FORW + lab]; | ||||||
| 	if (ip == 0) | 	if (ip == 0) | ||||||
|  | 	{ | ||||||
| 		if (pass == PASS_1) | 		if (pass == PASS_1) | ||||||
|  | 		{ | ||||||
| 			ip = fb_alloc(lab); | 			ip = fb_alloc(lab); | ||||||
|  | 		} | ||||||
| 		else | 		else | ||||||
|  | 		{ | ||||||
| 			ip = fb_ptr[FB_HEAD + lab]; | 			ip = fb_ptr[FB_HEAD + lab]; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	fb_ptr[FB_BACK + lab] = ip; | 	fb_ptr[FB_BACK + lab] = ip; | ||||||
| 	fb_ptr[FB_FORW + lab] = ip->i_next; | 	fb_ptr[FB_FORW + lab] = ip->i_next; | ||||||
| 	return (ip); | 	return (ip); | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ | ||||||
| #include	"comm0.h" | #include	"comm0.h" | ||||||
| #include	"comm1.h" | #include	"comm1.h" | ||||||
| #include	"y.tab.h" | #include	"y.tab.h" | ||||||
| #include	<object.h> | #include	"object.h" | ||||||
| 
 | 
 | ||||||
| static void new_common(item_t *); | static void new_common(item_t *); | ||||||
| 
 | 
 | ||||||
|  | @ -187,7 +187,7 @@ switchsect(int newtyp) | ||||||
| { | { | ||||||
| 	sect_t *sp; | 	sect_t *sp; | ||||||
| 	 | 	 | ||||||
| 	if (sp = DOTSCT) | 	if ((sp = DOTSCT)) | ||||||
| 		sp->s_size = DOTVAL - sp->s_base; | 		sp->s_size = DOTVAL - sp->s_base; | ||||||
| 	if (newtyp == S_UND) { | 	if (newtyp == S_UND) { | ||||||
| 		DOTSCT = NULL; | 		DOTSCT = NULL; | ||||||
|  | @ -212,10 +212,16 @@ align(valu_t bytes) | ||||||
| 	if (bytes == 0) | 	if (bytes == 0) | ||||||
| 		bytes = ALIGNWORD; | 		bytes = ALIGNWORD; | ||||||
| 	if (sp->s_lign % bytes) | 	if (sp->s_lign % bytes) | ||||||
|  | 	{ | ||||||
| 		if (bytes % sp->s_lign) | 		if (bytes % sp->s_lign) | ||||||
|  | 		{ | ||||||
| 			serror("illegal alignment"); | 			serror("illegal alignment"); | ||||||
|  | 		} | ||||||
| 		else | 		else | ||||||
|  | 		{ | ||||||
| 			sp->s_lign = bytes; | 			sp->s_lign = bytes; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	if (pass == PASS_1) | 	if (pass == PASS_1) | ||||||
| 		/*
 | 		/*
 | ||||||
| 		 * be pessimistic: biggest gap possible | 		 * be pessimistic: biggest gap possible | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ | ||||||
| #include "comm1.h" | #include "comm1.h" | ||||||
| #include "y.tab.h" | #include "y.tab.h" | ||||||
| #include <stdarg.h> | #include <stdarg.h> | ||||||
| #include <object.h> | #include "object.h" | ||||||
| 
 | 
 | ||||||
| valu_t load(const item_t* ip) | valu_t load(const item_t* ip) | ||||||
| { | { | ||||||
|  | @ -77,7 +77,7 @@ char* remember(char* s) | ||||||
| 		assert(nleft >= 0); | 		assert(nleft >= 0); | ||||||
| 	} | 	} | ||||||
| 	p = next; | 	p = next; | ||||||
| 	while (*p++ = *s++) | 	while ((*p++ = *s++)) | ||||||
| 		; | 		; | ||||||
| 	s = next; | 	s = next; | ||||||
| 	next = p; | 	next = p; | ||||||
|  | @ -133,7 +133,7 @@ int printx(int ndig, valu_t val) | ||||||
| 	} while (--n); | 	} while (--n); | ||||||
| 	do | 	do | ||||||
| 	{ | 	{ | ||||||
| 		c = "0123456789ABCDEF"[*--p]; | 		c = "0123456789ABCDEF"[(unsigned char)*--p]; | ||||||
| 		putchar(c); | 		putchar(c); | ||||||
| 	} while (p > buf); | 	} while (p > buf); | ||||||
| 	return (ndig); | 	return (ndig); | ||||||
|  | @ -232,6 +232,8 @@ int small(int fitsmall, int gain) | ||||||
| 		case PASS_3: | 		case PASS_3: | ||||||
| 			assert(fitsmall || (*p & bit) == 0); | 			assert(fitsmall || (*p & bit) == 0); | ||||||
| 			return (*p & bit); | 			return (*p & bit); | ||||||
|  | 		default: | ||||||
|  | 			assert(0); | ||||||
| 	} | 	} | ||||||
| 	/*NOTREACHED*/ | 	/*NOTREACHED*/ | ||||||
| } | } | ||||||
|  | @ -368,7 +370,7 @@ void emitstr(int zero) | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #define gen1 emit1 | #define gen1 emit1 | ||||||
| #include <con_float> | #include "con_float" | ||||||
| 
 | 
 | ||||||
| void emitf(int size, int negative) | void emitf(int size, int negative) | ||||||
| { | { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue