summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2012-07-02 10:34:30 -0600
committerBrian Paul <brianp@vmware.com>2012-07-31 12:46:44 -0600
commitf4df91ca23fdcd42d4918a08d6f8dc2bcd253e28 (patch)
tree46843290ec38c18c3141f9d5c9a922577a88ab74
parentcf0002531e14518b4a28f1fd80c4baeb6e099e31 (diff)
util: check for valid file type in piglit_load_text_file()
Piglit would segfault if piglit_load_text_file() was accidentally passed a directory name instead of a filename. Now return NULL if the file is not regular or a symlink.
-rw-r--r--tests/util/piglit-util.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 4ea87b016..5cbef8ec6 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -304,6 +304,13 @@ char *piglit_load_text_file(const char *file_name, unsigned *size)
if (fstat(fd, & st) == 0) {
ssize_t total_read = 0;
+ if (!S_ISREG(st.st_mode) &&
+ !S_ISLNK(st.st_mode)) {
+ /* not a regular file or symlink */
+ close(fd);
+ return NULL;
+ }
+
text = malloc(st.st_size + 1);
if (text != NULL) {
do {