From: mmayer@broadcom.com (Markus Mayer)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/1] Fix segfault in DTC
Date: Mon, 24 Sep 2012 15:48:05 -0700 [thread overview]
Message-ID: <1348526885-2113-2-git-send-email-mmayer@broadcom.com> (raw)
In-Reply-To: <1348526885-2113-1-git-send-email-mmayer@broadcom.com>
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.
Without the fix:
$ ./dtc /dev/null
DTC: dts->dts on file "/dev/null"
Segmentation fault (core dumped)
$ gdb dtc core
Program terminated with signal 11, Segmentation fault.
at scripts/dtc/srcpos.c:194
194 fname = pos->file->name;
(gdb) bt
at scripts/dtc/srcpos.c:194
fmt=0x40d769 "%s", va=0x7fffbf027148) at scripts/dtc/srcpos.c:220
at scripts/dtc/dtc-parser.tab.c:1920
at scripts/dtc/treesource.c:38
at scripts/dtc/dtc.c:203
(gdb) p *pos
$1 = {first_line = 0, first_column = 0, last_line = 0, last_column = 0,
file = 0x0}
With the fix:
$ ./dtc /dev/null
DTC: dts->dts on file "/dev/null"
Error: /dev/null:1.1 syntax error
FATAL ERROR: Unable to parse input tree
Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
scripts/dtc/treesource.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/scripts/dtc/treesource.c b/scripts/dtc/treesource.c
index c09aafa..b461b88 100644
--- a/scripts/dtc/treesource.c
+++ b/scripts/dtc/treesource.c
@@ -29,11 +29,15 @@ int treesource_error;
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);
if (yyparse() != 0)
die("Unable to parse input tree\n");
--
1.7.5.4
next prev parent reply other threads:[~2012-09-24 22:48 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-24 22:48 [PATCH 0/1] Fix segfault in DTC Markus Mayer
2012-09-24 22:48 ` Markus Mayer [this message]
2012-09-25 11:07 ` Will Deacon
2012-09-25 15:44 ` Stephen Warren
2012-09-25 16:42 ` Markus Mayer
2012-09-25 17:58 ` Markus Mayer
2012-09-25 17:58 ` [PATCH 1/1] " Markus Mayer
2012-09-25 23:30 ` David Gibson
2012-09-25 23:51 ` Markus Mayer
2012-09-26 0:35 ` David Gibson
2012-09-26 16:38 ` Markus Mayer
2012-09-28 17:09 ` Stephen Warren
2012-09-28 18:53 ` Jon Loeliger
2012-09-28 19:05 ` Stephen Warren
2012-09-28 20:32 ` Jon Loeliger
2012-09-29 23:53 ` David Gibson
2012-10-01 5:34 ` Stephen Warren
2012-10-01 6:46 ` David Gibson
2012-10-01 16:41 ` Stephen Warren
2012-10-02 0:08 ` David Gibson
2012-10-03 21:33 ` Stephen Warren
2012-10-04 4:49 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1348526885-2113-2-git-send-email-mmayer@broadcom.com \
--to=mmayer@broadcom.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).