diff options
author | Rui Paulo <rpaulo@FreeBSD.org> | 2014-06-10 06:04:25 +0000 |
---|---|---|
committer | Rui Paulo <rpaulo@FreeBSD.org> | 2014-06-10 06:04:25 +0000 |
commit | 23afbfa96ed53c164d7d789d090e4ecd5187955a (patch) | |
tree | 05321c98b27c5be1d06db210bcbfebd50bcc4161 /usr.bin/dtc | |
parent | b60aab01016656ac4e4f89af1bf6d8adc0ac72f6 (diff) | |
download | src-test-23afbfa96ed53c164d7d789d090e4ecd5187955a.tar.gz src-test-23afbfa96ed53c164d7d789d090e4ecd5187955a.zip |
dtc: don't crash if the argument is a directory.
Notes
Notes:
svn path=/head/; revision=267317
Diffstat (limited to 'usr.bin/dtc')
-rw-r--r-- | usr.bin/dtc/fdt.cc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/usr.bin/dtc/fdt.cc b/usr.bin/dtc/fdt.cc index 9998e8c211664..082ebd993d799 100644 --- a/usr.bin/dtc/fdt.cc +++ b/usr.bin/dtc/fdt.cc @@ -42,6 +42,8 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> #include "dtb.hh" namespace dtc @@ -1078,6 +1080,13 @@ device_tree::buffer_for_file(const char *path) fprintf(stderr, "Unable to open file %s\n", path); return 0; } + struct stat st; + if (fstat(source, &st) == 0 && S_ISDIR(st.st_mode)) + { + fprintf(stderr, "File %s is a directory\n", path); + close(source); + return 0; + } input_buffer *b = new mmap_input_buffer(source); // Keep the buffer that owns the memory around for the lifetime // of this FDT. Ones simply referring to it may have shorter |