]> git.p6c8.net - jirafeau/jirafeau.git/blobdiff - lib/functions.php
Check async ref files before opening.
[jirafeau/jirafeau.git] / lib / functions.php
index 6c8d56db6b839b9d7cf6fc786be1d00540587eca..0676c6fdd1a996586b192b03fdf125bde9ca9f56 100644 (file)
@@ -1022,11 +1022,16 @@ function jirafeau_get_async_ref($ref)
     $out = array();
     $refinfos = VAR_ASYNC . s2p("$ref") . "$ref";
 
-    if (!file_exists($refinfos)) {
+    if (!is_file($refinfos)) {
         return $out;
     }
 
     $c = file($refinfos);
+
+    if(empty($c)) {
+        return $out;
+    }
+
     $out['file_name'] = trim($c[0]);
     $out['mime_type'] = trim($c[1]);
     $out['key'] = trim($c[2], NL);
@@ -1120,6 +1125,11 @@ function jirafeau_async_init($filename, $type, $one_time, $key, $time, $ip)
   */
 function jirafeau_async_push($ref, $data, $code, $max_file_size)
 {
+    /* Validate ref string. */
+    if (!ctype_xdigit(trim($ref))) {
+        return "Error: Malformed ref string";
+    }
+
     /* Get async infos. */
     $a = jirafeau_get_async_ref($ref);
 
@@ -1127,6 +1137,7 @@ function jirafeau_async_push($ref, $data, $code, $max_file_size)
     if (count($a) == 0) {
         return "Error: cannot find transfer";
     }
+
     if ($a['next_code'] != "$code") {
         return "Error: bad transfer code";
     }
@@ -1193,6 +1204,11 @@ function jirafeau_async_push($ref, $data, $code, $max_file_size)
   */
 function jirafeau_async_end($ref, $code, $crypt, $link_name_length, $file_hash_method)
 {
+    /* Validate ref string. */
+    if (!ctype_xdigit(trim($ref))) {
+        return "Error: Malformed ref string";
+    }
+
     /* Get async infos. */
     $a = jirafeau_get_async_ref($ref);
     if (count($a) == 0

patrick-canterino.de