[Nasm-commits] [nasm:nasm-2.15.xx] preproc: error out if an include file exists but can't be opened
nasm-bot for H. Peter Anvin (Intel)
hpa at zytor.com
Thu Jun 4 19:56:58 PDT 2020
Commit-ID: 5d68f9823e6a4198b8fec73b03c1d0125a2aa6a8
Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=5d68f9823e6a4198b8fec73b03c1d0125a2aa6a8
Author: H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Mon, 1 Jun 2020 12:32:35 -0700
Committer: H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Mon, 1 Jun 2020 12:32:35 -0700
preproc: error out if an include file exists but can't be opened
If an include file exists, but cannot be opened, that is still a
critical error.
However, downgrade this from a fatal to a nonfatal error. There really
isn't any reason to stop cold here.
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>
---
asm/preproc.c | 15 +++++++++------
include/compiler.h | 1 +
test/include-self.asm | 2 ++
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/asm/preproc.c b/asm/preproc.c
index e3014f3e..b9f829ab 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -2241,12 +2241,15 @@ static FILE *inc_fopen(const char *file,
strlist_add(dhead, file);
}
- if (!path) {
- if (omode == INC_NEEDED)
- nasm_fatal("unable to open include file `%s'", file);
- } else {
- if (!fp && omode != INC_PROBE)
- fp = nasm_open_read(path, fmode);
+ if (path && !fp && omode != INC_PROBE)
+ fp = nasm_open_read(path, fmode);
+
+ if (omode == INC_NEEDED && !fp) {
+ if (!path)
+ errno = ENOENT;
+
+ nasm_nonfatal("unable to open include file `%s': %s",
+ file, strerror(errno));
}
if (found_path)
diff --git a/include/compiler.h b/include/compiler.h
index 04cab173..7c937988 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -88,6 +88,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
diff --git a/test/include-self.asm b/test/include-self.asm
new file mode 100644
index 00000000..234e8ea4
--- /dev/null
+++ b/test/include-self.asm
@@ -0,0 +1,2 @@
+; Test an infinite %include loop
+%include "include-self.asm"
More information about the Nasm-commits
mailing list