stat: check that TEMP environment variable is half-way sane

Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/stat.c b/stat.c
index 509c6f0..5a553d0 100644
--- a/stat.c
+++ b/stat.c
@@ -1494,8 +1494,11 @@
 		return 0;
 
 	temp_dir = getenv("TMPDIR");
-	if (temp_dir == NULL)
+	if (temp_dir == NULL) {
 		temp_dir = getenv("TEMP");
+		if (temp_dir && strlen(temp_dir) >= PATH_MAX)
+			temp_dir = NULL;
+	}
 	if (temp_dir == NULL)
 		temp_dir = "/tmp";