summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrpaulo <rpaulo@FreeBSD.org>2014-06-10 06:04:25 +0000
committerrpaulo <rpaulo@FreeBSD.org>2014-06-10 06:04:25 +0000
commit64f82214b7403af0a60fe51e905eb9f895583798 (patch)
tree05321c98b27c5be1d06db210bcbfebd50bcc4161
parent383a7fac3ea2aacf0fdfc13b17fb9ada0ca4421d (diff)
downloadFreeBSD-src-64f82214b7403af0a60fe51e905eb9f895583798.zip
FreeBSD-src-64f82214b7403af0a60fe51e905eb9f895583798.tar.gz
dtc: don't crash if the argument is a directory.
-rw-r--r--usr.bin/dtc/fdt.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/usr.bin/dtc/fdt.cc b/usr.bin/dtc/fdt.cc
index 9998e8c..082ebd9 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
OpenPOWER on IntegriCloud