nasm/output
Slavik Gnatenko 1b67bd25b2 BR 2010180: outobj: Garbage may be written in a last PUBDEF
The testcase illustrates the problem. After "nasm -f obj
alonesym.nasm"
let's look to dump:

======
PUBDEF386(91) recnum:5, offset:0000005bh, len:03f9h, chksum:bbh(bb)
Group: 0, Seg: 1
00020000h - 'sym0000' Type:0
00020004h - 'sym0001' Type:0
....
00020134h - 'sym0077' Type:0

PUBDEF(90) recnum:6, offset:00000457h, len:000ah, chksum:b6h(b6)
Group: 0, Seg: 1
00000138h - 's' Type:2
0000b600h - '' Type:0
======

The problem is while 's' offset is 20138h it is marked as type 90h not
91h.  The root cause is located in obj_x():

static ObjRecord *obj_x(ObjRecord * orp, uint32_t val)
{
    if (orp->type & 1)
    	orp->x_size = 32;
    if (val > 0xFFFF)
        orp = obj_force(orp, 32);
    if (orp->x_size == 32)
        return (obj_dword(orp, val));
    orp->x_size = 16;
    return (obj_word(orp, val));
}

It sets up x_size and than writes data. In the testcase data are the
offset and this offset overflows a record. In this case the record is
emitted and its x_size is cleared. Because this is last PUBDEF the new
record with only 's' symbol is emitted also but its x_size is not 32
(it's still zero) so obj_fwrite doesn't switch to 91h type.

The problem seems to be very generic and expected to be occurred on
many other record types as well.

        ----

And the fix is simple:

if (orp->x_size == 32)
{
  ObjRecord * nxt = obj_dword(orp, val);
  nxt->x_size = 32; /* x_size is cleared when a record overflows */
  return nxt;
}
2008-07-19 19:27:41 -07:00
..
outaout.c ctype.h: wrapper ctype functions with a cast to (unsigned char) 2008-06-21 10:23:17 -07:00
outaout.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outas86.c Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outas86.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outbin.c ctype.h: wrapper ctype functions with a cast to (unsigned char) 2008-06-21 10:23:17 -07:00
outbin.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outcoff.c ctype.h: wrapper ctype functions with a cast to (unsigned char) 2008-06-21 10:23:17 -07:00
outcoff.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outdbg.c regularized spelling of license to match name of LICENSE file 2007-12-29 09:44:23 -05:00
outelf32.c ctype.h: wrapper ctype functions with a cast to (unsigned char) 2008-06-21 10:23:17 -07:00
outelf64.c ctype.h: wrapper ctype functions with a cast to (unsigned char) 2008-06-21 10:23:17 -07:00
outelf.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outieee.c ctype.h: wrapper ctype functions with a cast to (unsigned char) 2008-06-21 10:23:17 -07:00
outmacho.c Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outmacho.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outobj.c BR 2010180: outobj: Garbage may be written in a last PUBDEF 2008-07-19 19:27:41 -07:00
outobj.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outrdf2.c ctype.h: wrapper ctype functions with a cast to (unsigned char) 2008-06-21 10:23:17 -07:00
outrdf2.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outrdf.c Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00
outrdf.mac Move the output format macros into the macros.pl mechanism 2008-06-20 15:20:16 -07:00