Repository: skalenetwork/filestorage (language: python)

Issue:
Bug/fix name checking



Discussion / hints:

Fix patch:
diff --git a/contracts/FileStorage.sol b/contracts/FileStorage.sol
index 35c07ca..bff1fd7 100644
--- a/contracts/FileStorage.sol
+++ b/contracts/FileStorage.sol
@@ -136,7 +136,7 @@ contract FileStorage is AccessControlEnumerableUpgradeable {
         require(currentDirectory.contents.length < getMaxContentCount(), "Directory is full");
         string memory pureFileName = (dirs.length > 1) ?  dirs[dirs.length - 1] : filePath;
         require(currentDirectory.contentIndexes[pureFileName] == EMPTY_INDEX, "File or directory exists");
-        require(Utils.checkContentName(pureFileName), "Filename should be < 256");
+        require(Utils.checkContentName(pureFileName), "Invalid filename");
         bool success = PrecompiledCaller.startUpload(owner, filePath, fileSize);
         require(success, "File not created");
         bool[] memory isChunkUploaded = new bool[]((fileSize + getMaxChunkSize() - 1) / getMaxChunkSize());
diff --git a/contracts/Utils.sol b/contracts/Utils.sol
index e2c6bba..22e94fe 100644
--- a/contracts/Utils.sol
+++ b/contracts/Utils.sol
@@ -34,6 +34,9 @@ library Utils {
     function checkContentName(string memory contentName) internal pure returns (bool) {
         if (keccak256(abi.encodePacked(contentName)) == keccak256(abi.encodePacked("..")) ||
         keccak256(abi.encodePacked(contentName)) == keccak256(abi.encodePacked(".")) ||
+        keccak256(abi.encodePacked(contentName)) == keccak256(abi.encodePacked("./")) ||
+        keccak256(abi.encodePacked(contentName)) == keccak256(abi.encodePacked("../")) ||
+        keccak256(abi.encodePacked(contentName)) == keccak256(abi.encodePacked("/")) ||
         bytes(contentName).length == 0) {
             return false;
         }


Test patch:
diff --git a/test/unit/createDirectory.test.js b/test/unit/createDirectory.test.js
index 6913d2e..84a2033 100644
--- a/test/unit/createDirectory.test.js
+++ b/test/unit/createDirectory.test.js
@@ -208,6 +208,18 @@ contract('Filestorage', accounts => {
             } catch (error) {
                 assert.equal(error.receipt.revertReason, 'Invalid directory name');
             }
+            try {
+                await filestorage.createDirectory('./', {from: accounts[0]});
+                assert.fail();
+            } catch (error) {
+                assert.equal(error.receipt.revertReason, 'Invalid directory name');
+            }
+            try {
+                await filestorage.createDirectory('../', {from: accounts[0]});
+                assert.fail();
+            } catch (error) {
+                assert.equal(error.receipt.revertReason, 'Invalid directory name');
+            }
             try {
                 await filestorage.createDirectory('', {from: accounts[0]});
                 assert.fail();
diff --git a/test/unit/startUpload.test.js b/test/unit/startUpload.test.js
index 1580a01..9b783c9 100644
--- a/test/unit/startUpload.test.js
+++ b/test/unit/startUpload.test.js
@@ -110,7 +110,7 @@ contract('Filestorage', accounts => {
                 await filestorage.startUpload(fileName, fileSize, {from: accounts[0]});
                 assert.fail('File was unexpectedly uploaded');
             } catch (error) {
-                assert.equal(error.receipt.revertReason, "Filename should be < 256");
+                assert.equal(error.receipt.revertReason, "Invalid filename");
             }
         });
 
@@ -119,19 +119,38 @@ contract('Filestorage', accounts => {
                 await filestorage.startUpload('', fileSize, {from: accounts[0]});
                 assert.fail('File was unexpectedly uploaded');
             } catch (error) {
-                assert.equal(error.receipt.revertReason, "Filename should be < 256");
+                assert.equal(error.receipt.revertReason, "Invalid filename");
             }
             try {
                 await filestorage.startUpload('.', fileSize, {from: accounts[0]});
                 assert.fail('File was unexpectedly uploaded');
             } catch (error) {
-                assert.equal(error.receipt.revertReason, "Filename should be < 256");
+                assert.equal(error.receipt.revertReason, "Invalid filename");
             }
             try {
                 await filestorage.startUpload('..', fileSize, {from: accounts[0]});
                 assert.fail('File was unexpectedly uploaded');
             } catch (error) {
-                assert.equal(error.receipt.revertReason, "Filename should be < 256");
+                assert.equal(error.receipt.revertReason, "Invalid filename");
+            }
+            try {
+                await filestorage.startUpload('./', fileSize, {from: accounts[0]});
+                assert.fail('File was unexpectedly uploaded');
+            } catch (error) {
+                assert.equal(error.receipt.revertReason, "Invalid filename");
+            }
+            try {
+                await filestorage.startUpload('../', fileSize, {from: accounts[0]});
+                assert.fail('File was unexpectedly uploaded');
+            } catch (error) {
+                assert.equal(error.receipt.revertReason, "Invalid filename");
+            }
+
+            try {
+                await filestorage.startUpload('/', fileSize, {from: accounts[0]});
+                assert.fail('File was unexpectedly uploaded');
+            } catch (error) {
+                assert.equal(error.receipt.revertReason, "Invalid filename");
             }
         });
 
@@ -141,13 +160,13 @@ contract('Filestorage', accounts => {
                 await filestorage.startUpload('dir/.', fileSize, {from: accounts[0]});
                 assert.fail('File was unexpectedly uploaded');
             } catch (error) {
-                assert.equal(error.receipt.revertReason, "Filename should be < 256");
+                assert.equal(error.receipt.revertReason, "Invalid filename");
             }
             try {
                 await filestorage.startUpload('dir/..', fileSize, {from: accounts[0]});
                 assert.fail('File was unexpectedly uploaded');
             } catch (error) {
-                assert.equal(error.receipt.revertReason, "Filename should be < 256");
+                assert.equal(error.receipt.revertReason, "Invalid filename");
             }
             await filestorage.deleteDirectory('dir', {from: accounts[0]});
         });