]> git.p6c8.net - jirafeau/pcanterino.git/blobdiff - lib/functions.php
During admin cleanup of expired files, consider an empty "time" value as an invalid...
[jirafeau/pcanterino.git] / lib / functions.php
index 07e5c02f7b3bb7a05667df4d433e2a9b3b6e3075..c7ef2680cfa6784b89076798b1f382335599156e 100644 (file)
@@ -862,7 +862,8 @@ function jirafeau_admin_clean()
                     continue;
                 }
                 $p = s2p($l['hash']);
                     continue;
                 }
                 $p = s2p($l['hash']);
-                if ($l['time'] > 0 && $l['time'] < time() || // expired
+                if (empty($l['time']) || // invalid
+                    $l['time'] > 0 && $l['time'] < time() || // expired
                     !file_exists(VAR_FILES . $p . $l['hash']) || // invalid
                     !file_exists(VAR_FILES . $p . $l['hash'] . '_count')) { // invalid
                     jirafeau_delete_link($node);
                     !file_exists(VAR_FILES . $p . $l['hash']) || // invalid
                     !file_exists(VAR_FILES . $p . $l['hash'] . '_count')) { // invalid
                     jirafeau_delete_link($node);
@@ -1022,11 +1023,16 @@ function jirafeau_get_async_ref($ref)
     $out = array();
     $refinfos = VAR_ASYNC . s2p("$ref") . "$ref";
 
     $out = array();
     $refinfos = VAR_ASYNC . s2p("$ref") . "$ref";
 
-    if (!file_exists($refinfos)) {
+    if (!is_file($refinfos)) {
         return $out;
     }
 
     $c = 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);
     $out['file_name'] = trim($c[0]);
     $out['mime_type'] = trim($c[1]);
     $out['key'] = trim($c[2], NL);
@@ -1075,9 +1081,9 @@ function jirafeau_async_init($filename, $type, $one_time, $key, $time, $ip)
     /* Create temporary folder. */
     $ref = '';
     $p = '';
     /* Create temporary folder. */
     $ref = '';
     $p = '';
-    $code = jirafeau_gen_random(4);
+    $code = jirafeau_gen_random(JIRAFEAU_ASYNC_CODE_LENGTH);
     do {
     do {
-        $ref = jirafeau_gen_random(32);
+        $ref = jirafeau_gen_random(JIRAFEAU_ASYNC_REF_LENGTH);
         $p = VAR_ASYNC . s2p($ref);
     } while (file_exists($p));
     @mkdir($p, 0755, true);
         $p = VAR_ASYNC . s2p($ref);
     } while (file_exists($p));
     @mkdir($p, 0755, true);
@@ -1120,11 +1126,19 @@ function jirafeau_async_init($filename, $type, $one_time, $key, $time, $ip)
   */
 function jirafeau_async_push($ref, $data, $code, $max_file_size)
 {
   */
 function jirafeau_async_push($ref, $data, $code, $max_file_size)
 {
+    $ref = trim($ref);
+    $code = trim($code);
+
     /* Validate ref string. */
     /* Validate ref string. */
-    if (!ctype_xdigit(trim($ref))) {
+    if (!ctype_xdigit($ref) || strlen($ref) != JIRAFEAU_ASYNC_REF_LENGTH) {
         return "Error: Malformed ref string";
     }
 
         return "Error: Malformed ref string";
     }
 
+    /* Validate code string. */
+    if (!ctype_xdigit($code) || strlen($code) != JIRAFEAU_ASYNC_CODE_LENGTH) {
+        return "Error: Malformed code string";
+    }
+
     /* Get async infos. */
     $a = jirafeau_get_async_ref($ref);
 
     /* Get async infos. */
     $a = jirafeau_get_async_ref($ref);
 
@@ -1132,7 +1146,8 @@ function jirafeau_async_push($ref, $data, $code, $max_file_size)
     if (count($a) == 0) {
         return "Error: cannot find transfer";
     }
     if (count($a) == 0) {
         return "Error: cannot find transfer";
     }
-    if ($a['next_code'] != "$code") {
+
+    if (!hash_equals($a['next_code'], "$code")) {
         return "Error: bad transfer code";
     }
     if ($data['error'] != UPLOAD_ERR_OK) {
         return "Error: bad transfer code";
     }
     if ($data['error'] != UPLOAD_ERR_OK) {
@@ -1198,18 +1213,30 @@ function jirafeau_async_push($ref, $data, $code, $max_file_size)
   */
 function jirafeau_async_end($ref, $code, $crypt, $link_name_length, $file_hash_method)
 {
   */
 function jirafeau_async_end($ref, $code, $crypt, $link_name_length, $file_hash_method)
 {
+    $ref = trim($ref);
+    $code = trim($code);
+
     /* Validate ref string. */
     /* Validate ref string. */
-    if (!ctype_xdigit(trim($ref))) {
+    if (!ctype_xdigit($ref) || strlen($ref) != JIRAFEAU_ASYNC_REF_LENGTH) {
         return "Error: Malformed ref string";
     }
 
         return "Error: Malformed ref string";
     }
 
+    /* Validate code string. */
+    if (!ctype_xdigit($code) || strlen($code) != JIRAFEAU_ASYNC_CODE_LENGTH) {
+        return "Error: Malformed code string";
+    }
+
     /* Get async infos. */
     $a = jirafeau_get_async_ref($ref);
     /* Get async infos. */
     $a = jirafeau_get_async_ref($ref);
-    if (count($a) == 0
-        || $a['next_code'] != "$code") {
-        return "Error: bad code for ending transfer";
+
+    /* Check some errors. */
+    if (count($a) == 0) {
+        return "Error: cannot find transfer";
     }
 
     }
 
+    if (!hash_equals($a['next_code'], "$code")) {
+        return "Error: bad code for ending transfer";
+    }
     /* Generate link infos. */
     $p = VAR_ASYNC . s2p($ref) . $ref . "_data";
     if (!file_exists($p)) {
     /* Generate link infos. */
     $p = VAR_ASYNC . s2p($ref) . $ref . "_data";
     if (!file_exists($p)) {

patrick-canterino.de