[Piglit] [PATCH] util: check for valid file type in piglit_load_text_file()

Brian Paul brianp at vmware.com
Mon Jul 2 09:36:34 PDT 2012


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.
---
 tests/util/piglit-util.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index f6c2ba0..888b8b8 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 {
-- 
1.7.7.3



More information about the Piglit mailing list