-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue #220] - dcRUSTy - Fix DOS vulnerability related to scanning sy…
…mlinks. * [Issue #220] - dcRUSTy - Fix bug that crashed test on Windows * [Issue #220] - dcRUSTy - Implement utility function wrapper for ioutil.ReadFile which skips following symlink
- Loading branch information
dcRUSTy
authored
Aug 13, 2020
1 parent
440eee6
commit 0855689
Showing
6 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ func Init(gitRoot string) *GitTesting { | |
os.MkdirAll(gitRoot, 0777) | ||
testingRepo := &GitTesting{gitRoot} | ||
testingRepo.ExecCommand("git", "init", ".") | ||
gitConfigFileObject, _ := ioutil.TempFile("/tmp", "gitConfigForTalismanTests") | ||
gitConfigFileObject, _ := ioutil.TempFile(os.TempDir(), "gitConfigForTalismanTests") | ||
gitConfigFile = gitConfigFileObject.Name() | ||
testingRepo.CreateFileWithContents(gitConfigFile, `[user] | ||
email = [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package utility | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestShouldReadNormalFileCorrectly(t *testing.T) { | ||
tempFile, _ := ioutil.TempFile(os.TempDir(), "somefile") | ||
dataToBeWrittenInFile := []byte{0, 1, 2, 3} | ||
tempFile.Write(dataToBeWrittenInFile) | ||
tempFile.Close() | ||
|
||
readDataFromFileUsingIoutilDotReadFile, _ := ioutil.ReadFile(tempFile.Name()) | ||
readDataFromFileUsingSafeFileRead, _ := SafeReadFile(tempFile.Name()) | ||
os.Remove(tempFile.Name()) | ||
|
||
assert.Equal(t, readDataFromFileUsingIoutilDotReadFile, dataToBeWrittenInFile) | ||
assert.Equal(t, readDataFromFileUsingSafeFileRead, dataToBeWrittenInFile) | ||
} | ||
|
||
func TestShouldNotReadSymbolicLinkTargetFile(t *testing.T) { | ||
tempFile, _ := ioutil.TempFile(os.TempDir(), "somefile") | ||
dataToBeWrittenInFile := []byte{0, 1, 2, 3} | ||
tempFile.Write(dataToBeWrittenInFile) | ||
tempFile.Close() | ||
symlinkFileName := tempFile.Name() + "symlink" | ||
os.Symlink(tempFile.Name(), symlinkFileName) | ||
|
||
readDataFromSymlinkUsingIoutilDotReadFile, _ := ioutil.ReadFile(symlinkFileName) | ||
readDataFromSymlinkUsingSafeFileRead, _ := SafeReadFile(symlinkFileName) | ||
os.Remove(symlinkFileName) | ||
os.Remove(tempFile.Name()) | ||
|
||
assert.Equal(t, readDataFromSymlinkUsingIoutilDotReadFile, dataToBeWrittenInFile) | ||
assert.Equal(t, readDataFromSymlinkUsingSafeFileRead, []byte{}) | ||
} |