[PATCH wayland] scanner: Print filename on DTD validation error

Bryce Harrington bryce at osg.samsung.com
Tue Feb 2 01:40:11 UTC 2016


On Tue, Jan 26, 2016 at 12:53:00PM -0600, Derek Foreman wrote:
> On 26/01/16 01:14 AM, Hardening wrote:
> > Le 25/01/2016 10:28, Jonas Ådahl a écrit :
> >> 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 at gmail.com>
> >> ---
> >>  src/scanner.c | 15 ++++++++++-----
> >>  1 file changed, 10 insertions(+), 5 deletions(-)
> > 
> > Reviewed-by: David Fort <contact at hardening-consulting.com>
> 
> and Reviewed-by: Derek Foreman <derekf at osg.samsung.com>

> Definitely an improvement.

LGTM too:

Reviewed-by: Bryce Harrington <bryce at osg.samsung.com>

And pushed:

To ssh://git.freedesktop.org/git/wayland/wayland
   0d56e38..7b42788  master -> master
 
> >>
> >> 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"
> >>
> > 
> > 
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list