summaryrefslogtreecommitdiff
path: root/treesource.c
diff options
context:
space:
mode:
authorHorst Kronstorfer <hkronsto@frequentis.com>2012-02-07 10:02:53 +0100
committerJon Loeliger <jdl@jdl.com>2012-02-16 06:43:51 -0600
commita6e6c60e3a97a6b3a033cd052bb3740fd53cbf4c (patch)
treef340f4db6218cf8729abd65cbb9944ad30608c69 /treesource.c
parente280442e08fcbe8431dc85d836ff3ecc489932fb (diff)
downloaddtc-a6e6c60e3a97a6b3a033cd052bb3740fd53cbf4c.tar.gz
dtc: Fix zero-length input segfault
This patch fixes a segmentation fault caused by dereferencing a NULL pointer (pos->file aka yylloc.file) in srcpos_string when the input length is 0 (fe 'dtc </dev/null'.) Reason: yylloc.file is initialized with 0 and the tokenizer, which updates yylloc.file via srcpos_update doesn't get a chance to run on zero-length input. Signed-off-by: Horst Kronstorfer <hkronsto@frequentis.com>
Diffstat (limited to 'treesource.c')
-rw-r--r--treesource.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/treesource.c b/treesource.c
index c09aafa..33eeba5 100644
--- a/treesource.c
+++ b/treesource.c
@@ -23,6 +23,7 @@
extern FILE *yyin;
extern int yyparse(void);
+extern YYLTYPE yylloc;
struct boot_info *the_boot_info;
int treesource_error;
@@ -34,6 +35,7 @@ struct boot_info *dt_from_source(const char *fname)
srcfile_push(fname);
yyin = current_srcfile->f;
+ yylloc.file = current_srcfile;
if (yyparse() != 0)
die("Unable to parse input tree\n");