diff options
author | Jonas Ådahl <jadahl@gmail.com> | 2016-01-25 17:28:06 +0800 |
---|---|---|
committer | Bryce Harrington <bryce@bryceharrington.org> | 2016-02-01 17:39:08 -0800 |
commit | 7b42788f212079c2ef4c69c095efa50e90ca1301 (patch) | |
tree | f0bc0c8e5ded60ece6895ce509d4fa6faefe2b8f | |
parent | 0d56e380f676e6fe475ffba71f11b480adf4e0a5 (diff) | |
download | wayland-7b42788f212079c2ef4c69c095efa50e90ca1301.tar.gz |
scanner: Print filename on DTD validation error
Don't just print prefix the errors with "protocol", but the actual file
name, if wayland-scanner was passed with the filename of the protocol
file. If wayland-scanner is reading from stdin, errors will be prefixed
with "<stdin>" instead of "protocol".
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: David Fort <contact@hardening-consulting.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
-rw-r--r-- | src/scanner.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/scanner.c b/src/scanner.c index 1d626f4..dda5473 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -71,7 +71,7 @@ usage(int ret) } static bool -is_dtd_valid(FILE *input) +is_dtd_valid(FILE *input, const char *filename) { bool rc = true; #if HAVE_LIBXML @@ -101,7 +101,7 @@ is_dtd_valid(FILE *input) abort(); } - doc = xmlCtxtReadFd(ctx, fd, "protocol", NULL, 0); + doc = xmlCtxtReadFd(ctx, fd, filename, NULL, 0); if (!doc) { fprintf(stderr, "Failed to read XML\n"); abort(); @@ -1623,6 +1623,7 @@ int main(int argc, char *argv[]) struct parse_context ctx; struct protocol protocol; FILE *input = stdin; + char *input_filename = NULL; int len; void *buf; bool help = false, core_headers = false; @@ -1678,7 +1679,8 @@ int main(int argc, char *argv[]) usage(EXIT_FAILURE); if (argc == 3) { - input = fopen(argv[1], "r"); + input_filename = argv[1]; + input = fopen(input_filename, "r"); if (input == NULL) { fprintf(stderr, "Could not open input file: %s\n", strerror(errno)); @@ -1700,9 +1702,12 @@ int main(int argc, char *argv[]) /* initialize context */ memset(&ctx, 0, sizeof ctx); ctx.protocol = &protocol; - ctx.loc.filename = "<stdin>"; + if (input == stdin) + ctx.loc.filename = "<stdin>"; + else + ctx.loc.filename = input_filename; - if (!is_dtd_valid(input)) { + if (!is_dtd_valid(input, ctx.loc.filename)) { fprintf(stderr, "*******************************************************\n" "* *\n" |