Commit graph

4796 commits

Author SHA1 Message Date
H. Peter Anvin
c115cf4864 Merge remote-tracking branch 'igg0/strcat' 2022-11-07 12:36:24 -08:00
H. Peter Anvin
665a9820f5 Merge remote-tracking branch 'vszakats/outcoff-file-repro' 2022-11-07 12:35:34 -08:00
zhrf2020
8fcc785f95 preproc: fix memory leak (and possibly CVEs?)
case PP_ENDM:
    case PP_ENDMACRO:
        if (!(defining && defining->name)) {
            nasm_nonfatal("`%s': not defining a macro", tok_text(tline));
            goto done;
        }
        mmhead = (MMacro **) hash_findi_add(&mmacros, defining->name);
        defining->next = *mmhead;
        *mmhead = defining;
        defining = NULL;
        break;

The variable: mmacros has not been released, which will cause a memory
leak. Repair cve-2021-33450 cve-2021-33452 synchronously

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 12:34:04 -08:00
H. Peter Anvin
0582a32300 Merge remote-tracking branch 'rygorous/master' 2022-11-07 12:31:54 -08:00
H. Peter Anvin
ffedb33c33 Merge remote-tracking branch 'lkslawek/master' 2022-11-07 12:26:13 -08:00
H. Peter Anvin
13e338af8b Merge remote-tracking branch 'iglosiggio/fix-DW_AT_high_pc-relocation' 2022-11-07 12:23:36 -08:00
Iouri Kharon
21d8dbfabb restire: Support of AVX512-FP16 Instructions
Add support for AVX512-FP16 instructions and the associated
handling. Allow "mapN" syntax as well as "mN" syntax to match the
documentation.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 12:21:23 -08:00
H. Peter Anvin
e87647e2c9 Merge remote-tracking branch 'photograveur/doc_unimacro' 2022-11-07 12:16:51 -08:00
H. Peter Anvin
a131b1129c preproc: fix use of free() instead of nasm_free()
free() and nasm_free() are required to be compatible (as we may end up
having memory allocated on the heap by the C library), but that
doesn't mean we shouldn't use it whereever possible to allow for
better debugging.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392804
Reported-by: C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 12:09:04 -08:00
H. Peter Anvin
7b8cd67d51 preproc: add warning for empty %{} construct
An empty %{} becomes % which is simply the arithmetic
operator. Although that is consistent, it might be surprising for
users, to issue a warning.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 12:01:00 -08:00
H. Peter Anvin
baae422e61 preproc: an empty %[] construct generates a null token, drop
%[] amounts to an empty token; this needs to be handled specially so
that it gets properly dropped.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392806
Reported-by: C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 11:47:22 -08:00
H. Peter Anvin
2d4e695241 quote_for_pmake: fix counter underrun resulting in segfault
while (nbs--) { ... } ends with nbs == -1. Rather than a minimal fix,
introduce mempset() to make these kinds of errors less likely in the
future.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392815
Reported-by: <13579and24680@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 10:26:03 -08:00
H. Peter Anvin
7a2b5c9221 x86/insns.dat: fix VCVTNEPS2BF16
The VCVTNEPS2BF16 instruction was incorrectly specified as
VCVTNE2S2BF16. Fortunately, the correct opcode for the latter was
specified first, so it would emit the correct result when that
instruction was specified.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392821
Reported-by: Agner <agner@agner.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 10:03:45 -08:00
H. Peter Anvin
7351302477 output/elf: remove efmt->rela_size
There are no use cases for of RELA on i386, and the intent has always been
that efmt->rel_size would be the size of the desired relocation
section type. Rename it from rel_size to relsize to make it more
obvious that it matches efmt->reltype rather than SHT_REL, and delete
efmt->rela_size to keep it from being misused again.

This should avoid a repeat of:

    https://bugzilla.nasm.us/show_bug.cgi?id=3392807

fixed in adf7507e29.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 09:54:33 -08:00
Kai Burghardt
d88660fc1e
document %imacro%unimacro (case-insensitive)
There is no documentation of the `%unimacro` directive.
This is particularly confusing when you’re trying to remove a macro
that has previously been defined with the `%imacro` directive.
2022-10-09 19:24:41 +00:00
H. Peter Anvin
bb1233ccde Add FRED instructions
Add the FRED instructions: ERETU, ERETS, LKGS

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 13:31:30 -07:00
H. Peter Anvin
91580319bc Merge remote-tracking branch 'github/nasm-2.15.xx' 2022-10-05 12:31:33 -07:00
H. Peter Anvin
b6bcd3a6dc NASM 2.16rc1 2022-10-05 12:15:06 -07:00
H. Peter Anvin
b6151260a1 configure.ac: update to autoconf 2.71 standard
autoconf 2.71 changes some macros and obsolete others; fix to match
autoconf 2.71 standard.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 12:09:36 -07:00
H. Peter Anvin
8453bcfa6c autoconf: update macros and helper scripts
Update the autoconf macros and helper scripts to the current versions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 12:03:33 -07:00
H. Peter Anvin
67fbb45816 rdoff/ldrdf.c: fix memory overflow errors causing build failures
The RDOFF tools are fundamentally broken to the core: they are
defining headers which contain misaligned structure members, which
cause the compiler to add padding, breaking the format.

This is just a build fix; remove RDOFF in 2.16.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 12:00:57 -07:00
Sławomir Bocheński
dffc514af7 Add test case for istruc's "at" with local labels
Signed-off-by: Sławomir Bocheński <lkslawek@gmail.com>
2022-09-09 00:30:24 +02:00
Sławomir Bocheński
5b9bcacebb Make istruc "at" support struc local labels
istruc currently does not work very well with passing local labels to
"at" macro, as the labels are inserted literally. E.g. considering the
example from test/struc.asm:

	struc teststruc1
	  .long: resd 1
	  .word: resw 1
	  .byte: resb 1
	  .str:  resb 32
	endstruc
	; ...
	istruc teststruc1
	 at .word, db 5
	iend

if one were to put a global label before istruc to refer to its
instance, the code would fail to compile, due to ".word" being unknown
in that scope. Of course one could then use full form after "at", i.e.
"teststruc1.word", but this seems rather tedious.

This also makes istruc use with local labels fail for anything but the
last declared struc.

The change automatically prepends struc name to the label if the label
given to "at" starts with a dot.

Signed-off-by: Sławomir Bocheński <lkslawek@gmail.com>
2022-09-09 00:30:06 +02:00
Cyrill Gorcunov
a8ff6bf771
Merge pull request #37 from hjl-tools/hjl/dwarf32
Use REL relocation in DWARF sections for i386
2022-09-06 11:06:35 +03:00
Ignacio Losiggio
eb5d3b7c6a
output/outelf: Fix relocation for DW_AT_high_pc
The information for DW_AT_high_pc was not correctly generated. Instead
of having a relocation whose value was `.text + highaddr` we wrote
`highaddr` to the output file location and added a relocation for
`.text + 0`.

This change writes `0` to the file and creates the correct relocation.
The previous behaviour wasn't noticed before because GNU ld had the
opposite issue: it added the target contents with the symbol value and
the entry addend. These two bugs coexisted in peace until GNU ld fixed
their broken interpretation of the spec on
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=17c6c3b99156fe82c1e637e1a5fd9f163ac788c8

This will fix broken debug information for binaries generated with lld
and newer ld versions.

`elf32` relocations are left untouched because the current behaviour
(emitting RELA relocations) is broken, see: https://github.com/netwide-assembler/nasm/pull/37

More information:
- https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html#chapter7-2
- https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/bfd-in2.h;h=4ab7e2d69347fc8d707094c18b29e1b32ecfcd69;hb=HEAD#l2063

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392798

Signed-off-by: Ignacio Losiggio <iglosiggio@dc.uba.ar>
2022-09-01 14:32:02 -03:00
H.J. Lu
adf7507e29 Use REL relocation in DWARF sections for i386
i386 should use REL relocation in DWARF sections with addend stored at
the relocation offset.  This fixes

https://bugzilla.nasm.us/show_bug.cgi?id=3392807

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2022-09-01 09:04:47 -07:00
Fabian Giesen
04f981e0e6 output/elf: Don't set data symbol type/size in ABS sections
I'm dealing with a FreeBSD-derived embedded target that ends up
showing such symbols (which is mainly NASM struct definitions)
in backtraces after calling NULL function pointers, since these
symbols _are_ technically covering bytes around address zero.

Needless to say, this is extremely confusing and generates
nonsensical bug reports. (Essentially, random unrelated crashes
get cross-referenced to a random ASM struct, whatever the linker
picked for address 0).

These symbols are already a bit strange to begin with (they're
purely an artifact of how NASM happens to implement structs),
leaving their sizes at 0 seems reasonable.

Signed-off-by: Fabian Giesen <fabian.giesen@epicgames.com>
2022-08-30 14:26:54 -07:00
Viktor Szakats
e1423b0573
omit input filename from COFF output when --reproducible
Before this patch, COFF output always contained the first 18 bytes of the
input filename. This breaks reproducibility and may also leak sensitive
data to objects (esp. with input filenames with absolute paths.)

This patch makes this output respect the --reproducible option, and omits
the input filename from the COFF output, when set.
2022-07-12 06:07:53 +00:00
Cyrill Gorcunov
3aebb20f12
Merge pull request #28 from Zildj1an/patch-1
Fix warning on ; outside of function
2022-05-10 23:59:32 +03:00
Carlos Bilbao
c0d902c6c2
Fix warning on ; outside of function
Fix "warning ISO C does not allow extra ‘;’ outside of a function" when using gcc v8.5. 
Signed-off-by: Carlos Bilbao <carlos.bilbao@amd.com>
2022-04-04 10:25:58 -05:00
Igor Glucksmann
349f19d402 Fixed optional comma separator in %strcat
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
2022-02-02 17:09:06 +01:00
Igor Glucksmann
3f9fc2a3a7 docs: Update comdat section attribute
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-12-17 23:45:51 +03:00
Igor Glucksmann
27e17c913c output/coff: Possibility to define the associated comdat sections in any order
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-12-17 23:45:39 +03:00
Igor Glucksmann
ed2c609976 output/coff: Support for COMDAT sections
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-12-17 23:45:25 +03:00
Cyrill Gorcunov
4b5224ba8f test: add dbxsize test
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-11-20 23:57:49 +03:00
Marco Bonelli
d167b3d4f3 Fix wrong size calculation for "Dx ?" larger than DB
The size calculation done in len_extops() (called by insn_size()) for
EOT_DB_RESERVE (i.e. uninitialized storage "?" token) does not take
into account the element size (e->elem), thus calculating a wrong
size for any Dx larger than DB (DW, DQ, etc).

The bug is silent, but it makes NASM error out if a "Dx ?" (larger
than DB) is followed by any label because the label offset gets
mismatched in the final code generation stage:

    $ cat test.asm
    [section .bss]
    DW ?
    x:

    $ nasm test.asm
    test.asm:3: error: label `x' changed during code generation [-w+error=label-redef-late]

See also: https://stackoverflow.com/q/70012188/3889449

Signed-off-by: Marco Bonelli <marco@mebeim.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-11-20 23:53:40 +03:00
Cyrill Gorcunov
00c6490620 BR3392776: parser: parse_line -- fix unitialized memory access
Andrew reported that we may access unitialized memory

> SUMMARY: MemorySanitizer: use-of-uninitialized-value nasm/asm/parser.c:982:41 in parse_line

It turns out that in case of malformed data the expression is terminator
itself so we should not "lookup ahead" for next one. Thus test for first
expression initially and if test passes check for terminator.

Reported-by: Andrew Bao <xiaobaozidi@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-10-18 00:21:05 +03:00
Cyrill Gorcunov
3a81150867
Merge pull request #15 from astiob/libass
preproc: fix misparsing of << as right shift
2021-09-22 21:33:40 +03:00
Oleg Oshmyan
80a4e8e454 preproc: fix misparsing of << as right shift
Regression in commit 20e0d616dc.

Independently discovered and fixed by C. Masloch:
https://bugzilla.nasm.us/show_bug.cgi?id=3392747

Signed-off-by: Oleg Oshmyan <chortos@inbox.lv>
2021-09-21 23:30:53 +03:00
Cyrill Gorcunov
e2ed7b7e12 x86/insns: add VMGEXIT
The instruction supports two forms with [f2] and [f3].
I guess we might add aliases as VMGEXIT2 and VMGEXIT3.
For now simly leave a second form for ndisasm sake.

https://bugzilla.nasm.us/show_bug.cgi?id=3392755

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 09:14:10 +03:00
Cyrill Gorcunov
c4babdf2db x86/insns: add RMPADJUST
https://bugzilla.nasm.us/show_bug.cgi?id=3392754

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:29:32 +03:00
Cyrill Gorcunov
1430995095 x86/insns: add PVALIDATE
https://bugzilla.nasm.us/show_bug.cgi?id=3392753

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:27:07 +03:00
Cyrill Gorcunov
984761f924 travis: add vmx test
To test VMX instructions.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:25:04 +03:00
Cyrill Gorcunov
39bb9d71a3 output/outelf: drop unused structure
The erel structure left from times when we've
been merging separate elf32/32x/64 files.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-09 00:59:38 +03:00
Marco Vanotti
f2a6eb4aac Add DW_AT_comp_dir to elf files.
This commit adds the compilation directory debug information for ELF files.
This feature helps debuggers locate the source file when debugging.
The feature is already present for Mach-O files.

Signed-off-by: Marco Vanotti <mvanotti@dc.uba.ar>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-08 23:59:09 +03:00
turekt
a9faae3e0b ndisasm: Stack buffer overflow fix
Changing the type of `to_read` from `uint32_t` to
`int32_t` makes it aware of negative numbers and fixes
the buffer overflow in ndisasm.

Signed-off-by: T Turek <tureqsec@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-05 00:30:55 +03:00
Cyrill Gorcunov
aa2dcdec09 travis: add br3392751
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-03 17:59:08 +03:00
Cyrill Gorcunov
02641a3c84 assemble: process_ea - fix unitialized read
In commit 2469b8b6 we occasionally bring the ability
to read unitialized memory due to refactoring. Fix it
doing needed test inside the function and setting up
an error message if needed.

Side note: passing 7 arguments into the function means
we have to decompose this helper somehow, such number
of arguments is a way over the top.

Bugzilla: https://bugzilla.nasm.us/show_bug.cgi?id=3392751
Reported-by: Marco <mvanotti@protonmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-03 17:55:32 +03:00
H. Peter Anvin
2469b8b66e Add {rex} prefix, simplify prefix handling, better error messages
Add a {rex} prefix to force REX encoding (typically a redundant 40h
prefix).

For prefix parsing, we can use t_inttwo to encode the prefix slot
number.

Give more verbose error messages for encoding mismatches.
2021-04-27 11:37:42 -07:00
H. Peter Anvin (Intel)
5368e45794 preproc: fix pasting of TOKEN_HERE, TOKEN_BASE and TOKEN_QMARK
Make the pasting behavior of TOKEN_QMARK, TOKEN_HERE and TOKEN_BASE
match the NASM 2.15 behavior: ? is a keyword and pastes as an ID, $
and $$ are treated as operators (which doesn't seem to make much
sense, but it is the current legacy behavior.)

Reported-by: C. Masloch <pushbx@ulukai.org>
Bugzilla: https://bugzilla.nasm.us/show_bug.cgi?id=3392733
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2021-03-24 10:46:45 -07:00