From: Peter Johnson Date: Sun, 4 Mar 2007 09:21:03 +0000 (-0000) Subject: Mach-O object format: 0-fill unused portion of section and segment names X-Git-Tag: v0.6.1~15^2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fb65a432b55d5164744102ff1ac2ab15899f199;p=yasm Mach-O object format: 0-fill unused portion of section and segment names in load commands. This caused test miscompares on other platforms and could conceivably cause yasm to crash by reading beyond proper boundaries (but this is unlikely). Functionally the output is the same. Reported by: christophe.malvasio1@aliceadsl.fr Backport in: 1 week svn path=/trunk/yasm/; revision=1811 --- diff --git a/modules/objfmts/macho/macho-objfmt.c b/modules/objfmts/macho/macho-objfmt.c index b0c79bc3..68db6adb 100644 --- a/modules/objfmts/macho/macho-objfmt.c +++ b/modules/objfmts/macho/macho-objfmt.c @@ -761,8 +761,12 @@ macho_objfmt_output_secthead(yasm_section *sect, /*@null@*/ void *d) localbuf = info->buf; - fwrite(msd->sectname, 16, 1, info->f); - fwrite(msd->segname, 16, 1, info->f); + memset(localbuf, 0, 16); + strncpy((char *)localbuf, msd->sectname, 16); + localbuf += 16; + memset(localbuf, 0, 16); + strncpy((char *)localbuf, msd->segname, 16); + localbuf += 16; /* section address, size depend on 32/64 bit mode */ YASM_WRITE_32_L(localbuf, msd->vmoff); /* address in memory */ if (info->is_64) @@ -800,9 +804,9 @@ macho_objfmt_output_secthead(yasm_section *sect, /*@null@*/ void *d) YASM_WRITE_32_L(localbuf, 0); /* reserved 2 */ if (info->is_64) - fwrite(info->buf, MACHO_SECTCMD64_SIZE - 32, 1, info->f); /* 2*16 byte strings already written */ + fwrite(info->buf, MACHO_SECTCMD64_SIZE, 1, info->f); else - fwrite(info->buf, MACHO_SECTCMD_SIZE - 32, 1, info->f); /* 2*16 byte strings already written */ + fwrite(info->buf, MACHO_SECTCMD_SIZE, 1, info->f); return 0; } diff --git a/modules/objfmts/macho/tests/gas32/gas-macho32.hex b/modules/objfmts/macho/tests/gas32/gas-macho32.hex index 5ab90a5a..72cdabde 100644 --- a/modules/objfmts/macho/tests/gas32/gas-macho32.hex +++ b/modules/objfmts/macho/tests/gas32/gas-macho32.hex @@ -89,15 +89,15 @@ fe 78 74 00 -2e -63 -6f -6e -73 -74 00 -5f -5f +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 54 @@ -105,15 +105,15 @@ fe 58 54 00 -5f -5f -74 -65 -78 -74 00 -2e -63 +00 +00 +00 +00 +00 +00 +00 +00 00 00 00 @@ -157,15 +157,15 @@ bc 74 61 00 -2e -73 -74 -61 -74 -69 -63 -5f -64 +00 +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 44 @@ -173,15 +173,15 @@ bc 54 41 00 -5f -5f -6d -6f -64 -5f -69 -6e -69 +00 +00 +00 +00 +00 +00 +00 +00 +00 41 00 00 @@ -224,16 +224,16 @@ f4 73 73 00 -2e -6f -62 -6a -63 -5f -63 -6c -61 -73 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 44 @@ -241,15 +241,15 @@ f4 54 41 00 -5f -5f -6d -6f -64 -5f -69 -6e -69 +00 +00 +00 +00 +00 +00 +00 +00 +00 81 00 00 diff --git a/modules/objfmts/macho/tests/gas64/gas-macho64.hex b/modules/objfmts/macho/tests/gas64/gas-macho64.hex index 09f1e8db..e4fa4882 100644 --- a/modules/objfmts/macho/tests/gas64/gas-macho64.hex +++ b/modules/objfmts/macho/tests/gas64/gas-macho64.hex @@ -109,15 +109,15 @@ c5 78 74 00 -2e -63 -6f -6e -73 -74 00 -5f -5f +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 54 @@ -125,15 +125,15 @@ c5 58 54 00 -5f -5f -74 -65 -78 -74 00 -2e -63 +00 +00 +00 +00 +00 +00 +00 +00 00 00 00 @@ -189,15 +189,15 @@ e8 74 61 00 -2e -73 -74 -61 -74 -69 -63 -5f -64 +00 +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 44 @@ -205,15 +205,15 @@ e8 54 41 00 -5f -5f -6d -6f -64 -5f -69 -6e -69 +00 +00 +00 +00 +00 +00 +00 +00 +00 5d 00 00 diff --git a/modules/objfmts/macho/tests/nasm32/macho-reloc.hex b/modules/objfmts/macho/tests/nasm32/macho-reloc.hex index 65406c5d..7ef6e8a1 100644 --- a/modules/objfmts/macho/tests/nasm32/macho-reloc.hex +++ b/modules/objfmts/macho/tests/nasm32/macho-reloc.hex @@ -89,15 +89,15 @@ f4 78 74 00 -2e -63 -6f -6e -73 -74 00 -5f -5f +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 54 @@ -105,15 +105,15 @@ f4 58 54 00 -5f -5f -74 -65 -78 -74 00 -2e -63 +00 +00 +00 +00 +00 +00 +00 +00 00 00 00 @@ -157,15 +157,15 @@ f4 74 61 00 -2e -73 -74 -61 -74 -69 -63 -5f -64 +00 +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 44 @@ -173,15 +173,15 @@ f4 54 41 00 -5f -5f -6d -6f -64 -5f -69 -6e -69 +00 +00 +00 +00 +00 +00 +00 +00 +00 28 00 00 diff --git a/modules/objfmts/macho/tests/nasm32/machotest.hex b/modules/objfmts/macho/tests/nasm32/machotest.hex index d1e36c5b..e6791e4e 100644 --- a/modules/objfmts/macho/tests/nasm32/machotest.hex +++ b/modules/objfmts/macho/tests/nasm32/machotest.hex @@ -89,15 +89,15 @@ fe 78 74 00 -2e -63 -6f -6e -73 -74 00 -5f -5f +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 54 @@ -105,15 +105,15 @@ fe 58 54 00 -5f -5f -74 -65 -78 -74 00 -2e -63 +00 +00 +00 +00 +00 +00 +00 +00 00 00 00 @@ -157,15 +157,15 @@ c0 74 61 00 -2e -73 -74 -61 -74 -69 -63 -5f -64 +00 +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 44 @@ -173,15 +173,15 @@ c0 54 41 00 -5f -5f -6d -6f -64 -5f -69 -6e -69 +00 +00 +00 +00 +00 +00 +00 +00 +00 47 00 00 @@ -224,16 +224,16 @@ f8 73 73 00 -2e -6f -62 -6a -63 -5f -63 -6c -61 -73 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 44 @@ -241,15 +241,15 @@ f8 54 41 00 -5f -5f -6d -6f -64 -5f -69 -6e -69 +00 +00 +00 +00 +00 +00 +00 +00 +00 87 00 00 diff --git a/modules/objfmts/macho/tests/nasm64/machotest64.hex b/modules/objfmts/macho/tests/nasm64/machotest64.hex index 46ecbc58..21395186 100644 --- a/modules/objfmts/macho/tests/nasm64/machotest64.hex +++ b/modules/objfmts/macho/tests/nasm64/machotest64.hex @@ -109,15 +109,15 @@ c6 78 74 00 -2e -63 -6f -6e -73 -74 00 -5f -5f +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 54 @@ -125,15 +125,15 @@ c6 58 54 00 -5f -5f -74 -65 -78 -74 00 -2e -63 +00 +00 +00 +00 +00 +00 +00 +00 00 00 00 @@ -189,15 +189,15 @@ c6 74 61 00 -2e -73 -74 -61 -74 -69 -63 -5f -64 +00 +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 44 @@ -205,15 +205,15 @@ c6 54 41 00 -5f -5f -6d -6f -64 -5f -69 -6e -69 +00 +00 +00 +00 +00 +00 +00 +00 +00 7a 00 00 @@ -268,16 +268,16 @@ ea 73 73 00 -2e -6f -62 -6a -63 -5f -63 -6c -61 -73 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 5f 5f 44 @@ -285,15 +285,15 @@ ea 54 41 00 -5f -5f -6d -6f -64 -5f -69 -6e -69 +00 +00 +00 +00 +00 +00 +00 +00 +00 c6 00 00