Re: [PATCH] Fix segfault in dtc when empty input file is given.

From: Stephen Warren
Date: Tue Sep 25 2012 - 11:44:25 EST


On 09/14/2012 04:23 PM, Markus Mayer wrote:
> Prior to this change, an empty input file would cause a segfault, because
> yylloc had never been initialized. There was never any characters for the
> lexer to match, so YY_USER_ACTION was never executed before the parse error
> was detected.
>
> When the parser printed the error message, it tried to include the name of
> the file, but the structure holding the file name (yylloc.file, referenced
> as pos->file) had never been initialized.

> diff --git a/scripts/dtc/treesource.c b/scripts/dtc/treesource.c

> struct boot_info *dt_from_source(const char *fname)
> {
> + extern YYLTYPE yylloc;
> +
> the_boot_info = NULL;
> treesource_error = 0;
>
> srcfile_push(fname);
> yyin = current_srcfile->f;
> + /* Initialize yylloc->file to avoid segfault on empty input */
> + srcpos_update(&yylloc, NULL, 0);

Wouldn't srcpos_update(&yyloc, fname, 0); be even more informative?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/