readnum returns 64bit number which may become
a negative integer upon conversion which in
turn lead to out of bound array access.
Fix it by explicit conversion with bounds check
| POC6:2: error: parameter count `2222222222' is out of bounds [0; 2147483647]
https://bugzilla.nasm.us/show_bug.cgi?id=3392528
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* commit '9a1216a1efa0ccb48e5df97acc763ea3de71e0ce':
NASM 2.14
nasmdoc.src: fix compound word
doc: Add a description for a useful case of mangling symbols
preproc: Don't access out of bound data on malformed input
rdstrnum: Make sure we dont shift out of bound
preproc: Fix out of bound access on malformed input
doc: Clarify %include search directory semantics
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
There are a number of places still where we test text
data which is potentially may be an empty string. This
is known to happen on fuzzer input but usually doesn't
take place in regular valid programs. Surely we need
to revisit preprocessor code for this kind of errors.
https://bugzilla.nasm.us/show_bug.cgi?id=3392525
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
A fuzzer revealed a problem in preproc code.
https://bugzilla.nasm.us/show_bug.cgi?id=3392521
Reported-by: ganshuitao <ganshuitao@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Use a hash table to enforce uniqueness in a string list. It is still
an ordered list, however, and can be walked in insertion order.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
All include paths to nasm must already have a trailing separator
prefix which is uncommon among tools. Change to using nasm_catfile
which gives a more normal behaviour.
https://bugzilla.nasm.us/show_bug.cgi?id=3392205
Signed-off-by: night199uk <night199uk@hermitcrabslab.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm-2.14.xx: (83 commits)
NASM 2.14rc16
doc: Update changes
preproc: expand_smacro -- Fix nil dereference on error path
eval: Eliminate division by zero
doc: Update changes
opflags: Convert is_class and is_reg_class to helpers
preproc: Fix out of range access in expand mmacro
doc: Update changes
parser: Fix sigsegv on certain equ instruction parsing
labels: Make sure nil label is never passed
labels: Don't nil dereference if no label provided
macho: Add warning message in macho_output()
macho/reloc: Fix addr size sensitive conditions
macho/reloc: Fix macho_output() to get the offset adjustments by add_reloc()
macho/reloc: Fixed offset adjustment in add_reloc()
macho/reloc: Allow absolute relocation when forcing a symbol reference
macho/reloc: Adjust SUB relocation information
macho/reloc: Fixed in handling GOT/GOTLOAD/TLV relocations
macho/reloc: Simplified relocation for REL/BRANCH
macho/sym: Record initial symbol number always
...
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
On specially crafetd malformed input file the params
might be zapped (say due to invalid syntax) so we might
access out of bound having nil dereference in best case.
Note the later code in this helper uses tok_isnt_ helper
which already has similar check.
https://bugzilla.nasm.us/show_bug.cgi?id=3392518
Reported-by: Jordan Zebor <j.zebor@f5.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Nearly all instances of nasm_fatal() and nasm_panic() take a flags
argument of zero. Simplify the code by making nasm_fatal and
nasm_panic default to no flags, and add an alternate version if flags
really are desired. This also means that every call site doesn't have
to initialize a zero argument.
Furthermore, ERR_NOFILE is now often not necessary, as the error code
will no longer cause a null reference if there is no current
file. Therefore, we can remove many instances of ERR_NOFILE which only
deprives the user of information.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Make all limit counters 64 bits, in case someone really has a usage
for an insanely large program. The globallines limit was omitted, add
it to the list of configurable limits.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Make all limit counters 64 bits, in case someone really has a usage
for an insanely large program. The globallines limit was omitted, add
it to the list of configurable limits.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Make any "deadman"-style execution limit configurable on the command
line (--limit-foo) or via a pragma (%pragma limit foo).
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Add --pragma to add pragmas on the command line; --before option to
add *any* statement on the command line, and add --include as an alias
for -P for familiarity with other toolchains.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Get rid of remaining dependencies on FILENAME_MAX, which ought to have
been removed a long time ago.
Remove ofmt->filename(); all implementations pretty much do the same
thing and there is absolutely no reason to duplicate that
functionality all over the place.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For specially formed code we can have skip_white_
to end up with nil pointer which should be taken
into account.
https://bugzilla.nasm.us/show_bug.cgi?id=3392435
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
In case if smacro is called with inapropriate
number of arguments exit early. Actually we have
to handle this situation more gracefully but
this requires a way more efforts than two
line patches (need to refactor macro expansion).
https://bugzilla.nasm.us/show_bug.cgi?id=3392431
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Use nasm_add_string_to_strlist() to avoid a memory leak.
nasm_add_to_strlist() requires that the caller manages the string
being added or not.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This fixes the dependency listings as generated with -MD (if
assembling runs in multiple passes).
https://bugzilla.nasm.us/show_bug.cgi?id=3392420
gorcunov@: add missing zero byte
Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In some circumstantes this free is incorrect resulting
in usage after-free. Workaround it by not freeing memory
here.
https://bugzilla.nasm.us/show_bug.cgi?id=3392414
gorcunov@:
- slightly tuneup the comment
Signed-off-by: Adam Majer <amajer@suse.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Move directive processing to its own file, and move nasmlib/error.c to
asm/error.c (it was not used by the disassembler); remove some extern
declarations from .c files, and do some general code cleanups.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
In commits e1f985c167 and f7606613d0
we reordered macros handling, but ofmt specific
macros are to be handled after standart ones
are processed.
In particular __SECT__ handling must not change,
so the order of inclusion does matter.
https://bugzilla.nasm.us/show_bug.cgi?id=3392376
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Fix pvs-studio error 'V501 There are identical sub-expressions
'(c) == '_'' to the left and to the right of the '||' operator.'. isnumchar()
is a macro defined as (nasm_isalnum(c) || (c) == '_')
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Plumb the %pragma directive through the preprocessor and make it
generate an assembly directive unless given as %pragma preproc. So
far no actual pragmas are actually defined.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
We search the dependency list anyway (ouch...) so we might as well
use that instead of keeping track of a tail pointer.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Always return found_path as a constant string. We end up making an
internal copy of it anyway to put in the fullpath hash, so there is no
reason to make a duplicate of it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We have been doing a pathname search every time we encounter a file,
which means every file in every pass. Instead, put the pathnames
found in a hash table.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
A number of fairly common operations are invoked way too many times,
especially when using incbin. Drastically reduce the number of system
calls that need to be executed, and use memory mapping to reduce
unnecessary double buffering.
We could improve this further by leaving files open once used;
however, that might run into file count problems on some systems.
Still unclear is why we seem to invoke nasm_file_size() twice per pass
for incbin.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
The ordering of the macro sets ended up changing due to the recent
file reorganization. Instead of forcing the order again, handle
multiple macro sets (rather than just two) in a coherent manner.
macros/macros.pl could use a cleanup of duplicated code, however.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Make the source code easier to understand and keep track of by
organizing it into subdirectories depending on the function.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>