mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-04-05 07:15:46 -04:00
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>
This commit is contained in:
parent
0d56e380f6
commit
7b42788f21
1 changed files with 10 additions and 5 deletions
|
|
@ -71,7 +71,7 @@ usage(int ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_dtd_valid(FILE *input)
|
is_dtd_valid(FILE *input, const char *filename)
|
||||||
{
|
{
|
||||||
bool rc = true;
|
bool rc = true;
|
||||||
#if HAVE_LIBXML
|
#if HAVE_LIBXML
|
||||||
|
|
@ -101,7 +101,7 @@ is_dtd_valid(FILE *input)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
doc = xmlCtxtReadFd(ctx, fd, "protocol", NULL, 0);
|
doc = xmlCtxtReadFd(ctx, fd, filename, NULL, 0);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
fprintf(stderr, "Failed to read XML\n");
|
fprintf(stderr, "Failed to read XML\n");
|
||||||
abort();
|
abort();
|
||||||
|
|
@ -1623,6 +1623,7 @@ int main(int argc, char *argv[])
|
||||||
struct parse_context ctx;
|
struct parse_context ctx;
|
||||||
struct protocol protocol;
|
struct protocol protocol;
|
||||||
FILE *input = stdin;
|
FILE *input = stdin;
|
||||||
|
char *input_filename = NULL;
|
||||||
int len;
|
int len;
|
||||||
void *buf;
|
void *buf;
|
||||||
bool help = false, core_headers = false;
|
bool help = false, core_headers = false;
|
||||||
|
|
@ -1678,7 +1679,8 @@ int main(int argc, char *argv[])
|
||||||
usage(EXIT_FAILURE);
|
usage(EXIT_FAILURE);
|
||||||
|
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
input = fopen(argv[1], "r");
|
input_filename = argv[1];
|
||||||
|
input = fopen(input_filename, "r");
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
fprintf(stderr, "Could not open input file: %s\n",
|
fprintf(stderr, "Could not open input file: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
@ -1700,9 +1702,12 @@ int main(int argc, char *argv[])
|
||||||
/* initialize context */
|
/* initialize context */
|
||||||
memset(&ctx, 0, sizeof ctx);
|
memset(&ctx, 0, sizeof ctx);
|
||||||
ctx.protocol = &protocol;
|
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,
|
fprintf(stderr,
|
||||||
"*******************************************************\n"
|
"*******************************************************\n"
|
||||||
"* *\n"
|
"* *\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue