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

Brian Paul brianp at vmware.com
Fri Jul 20 11:32:46 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 4ea87b0..5cbef8e 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.3.4



More information about the Piglit mailing list