Fix buffer overflow issue.

This commit is contained in:
carl 2019-03-25 00:13:42 +08:00
parent dcc2be5e8c
commit a6120c220e
4 changed files with 26 additions and 11 deletions

View file

@ -15,7 +15,7 @@
#include "comm0.h"
#include "comm1.h"
#include "y.tab.h"
#include <object.h>
#include "object.h"
extern YYSTYPE yylval;
@ -243,7 +243,8 @@ archive(void) {
if (needed()) {
fseek(input,offset,0);
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));
}
offset += header.ar_size;
@ -330,7 +331,7 @@ parse(char *s)
*/
#ifdef ASLD
for (i = 0; i < H_SIZE; i++) {
while (ip = hashtab[H_LOCAL+i]) {
while ((ip = hashtab[H_LOCAL+i])) {
/*
* cleanup local queue
*/

View file

@ -439,7 +439,7 @@ static int innumber(int c)
if (radix != 16 && (c == 'f' || c == 'b'))
return (infbsym(num));
yylval.y_valu = 0;
while (c = *p++)
while ((c = *p++))
{
if (c > '9')
c -= ('a' - '9' - 1);
@ -593,7 +593,7 @@ int hash(const char* p)
int c;
h = 0;
while (c = *p++)
while ((c = *p++))
{
h <<= 2;
h += c;
@ -668,10 +668,16 @@ item_t* fb_shift(int lab)
ip = fb_ptr[FB_FORW + lab];
if (ip == 0)
{
if (pass == PASS_1)
{
ip = fb_alloc(lab);
}
else
{
ip = fb_ptr[FB_HEAD + lab];
}
}
fb_ptr[FB_BACK + lab] = ip;
fb_ptr[FB_FORW + lab] = ip->i_next;
return (ip);

View file

@ -11,7 +11,7 @@
#include "comm0.h"
#include "comm1.h"
#include "y.tab.h"
#include <object.h>
#include "object.h"
static void new_common(item_t *);
@ -187,7 +187,7 @@ switchsect(int newtyp)
{
sect_t *sp;
if (sp = DOTSCT)
if ((sp = DOTSCT))
sp->s_size = DOTVAL - sp->s_base;
if (newtyp == S_UND) {
DOTSCT = NULL;
@ -212,10 +212,16 @@ align(valu_t bytes)
if (bytes == 0)
bytes = ALIGNWORD;
if (sp->s_lign % bytes)
{
if (bytes % sp->s_lign)
{
serror("illegal alignment");
}
else
{
sp->s_lign = bytes;
}
}
if (pass == PASS_1)
/*
* be pessimistic: biggest gap possible

View file

@ -13,7 +13,7 @@
#include "comm1.h"
#include "y.tab.h"
#include <stdarg.h>
#include <object.h>
#include "object.h"
valu_t load(const item_t* ip)
{
@ -77,7 +77,7 @@ char* remember(char* s)
assert(nleft >= 0);
}
p = next;
while (*p++ = *s++)
while ((*p++ = *s++))
;
s = next;
next = p;
@ -133,7 +133,7 @@ int printx(int ndig, valu_t val)
} while (--n);
do
{
c = "0123456789ABCDEF"[*--p];
c = "0123456789ABCDEF"[(unsigned char)*--p];
putchar(c);
} while (p > buf);
return (ndig);
@ -232,6 +232,8 @@ int small(int fitsmall, int gain)
case PASS_3:
assert(fitsmall || (*p & bit) == 0);
return (*p & bit);
default:
assert(0);
}
/*NOTREACHED*/
}
@ -368,7 +370,7 @@ void emitstr(int zero)
#endif
#define gen1 emit1
#include <con_float>
#include "con_float"
void emitf(int size, int negative)
{