Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SECURITY] Fix Temporary File Information Disclosure Vulnerability #440

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/test/java/com/aliyun/oss/common/utils/AuthUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;

import static com.aliyun.oss.common.utils.AuthUtils.loadPrivateKeyFromFile;
import static com.aliyun.oss.common.utils.AuthUtils.loadPublicKeyFromFile;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void testLoadPrivateKeyFromFile() {
public void testLoadNonRsaPrivateKeyFromFile() {
File file = null;
try {
file = File.createTempFile("test-private-key", ".pem");
file = Files.createTempFile("test-private-key", ".pem").toFile();
file.deleteOnExit();
String privateKeyContent = "-----BEGIN PRIVATE KEY-----\n" +
"abc\n" +
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/com/aliyun/oss/common/utils/IniEditorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import junit.framework.*;

import java.io.*;
import java.nio.file.Files;
import java.util.*;

public class IniEditorTest extends TestCase {
Expand Down Expand Up @@ -307,7 +308,7 @@ public void testSave() throws IOException {
i.set("test", "hallo", "velo");
i.addComment("test", "english");
i.set("test", "hello", "bike");
File f = File.createTempFile("test", null);
File f = Files.createTempFile("test", null).toFile();
// with output stream
i.save(new FileOutputStream(f));
Object[] saved = fileToStrings(f);
Expand All @@ -331,7 +332,7 @@ public void testSaveLoadCharset() throws IOException {
IniEditor i = new IniEditor("cšmmšn");
i.addSection("tŽst");
i.set("tŽst", "h‰llo", "vel›");
File f = File.createTempFile("test", null);
File f = Files.createTempFile("test", null).toFile();
i.save(new OutputStreamWriter(new FileOutputStream(f), charsetName));
i = new IniEditor("cšmmšn");
i.load(new InputStreamReader(new FileInputStream(f), charsetName));
Expand All @@ -345,7 +346,7 @@ public void testLoadClosingStream() throws IOException {
IniEditor i = new IniEditor();
i.addSection("test");
i.set("test", "hallo", "velo");
File f = File.createTempFile("test", null);
File f = Files.createTempFile("test", null).toFile();
i.save(f.toString());
i = new IniEditor();
i.load(f);
Expand Down Expand Up @@ -384,7 +385,7 @@ public void testSetOptionFormat() throws IOException {
i.setOptionFormatString("%s%s%s");
i.addSection("test");
i.set("test", "hallo", "velo");
File f = File.createTempFile("test", null);
File f = Files.createTempFile("test", null).toFile();
i.save(new FileOutputStream(f));
Object[] saved = fileToStrings(f);
assertEquals("hallo=velo", saved[1]);
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/com/aliyun/oss/common/utils/IniSectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import junit.framework.*;

import java.io.*;
import java.nio.file.Files;
import java.util.*;

public class IniSectionTest extends TestCase {
Expand Down Expand Up @@ -150,7 +151,7 @@ public void testSave() throws IOException {
s.set("hallo", "velo");
s.addComment("english");
s.set("hello", "bike");
File f = File.createTempFile("test", null);
File f = Files.createTempFile("test", null).toFile();
s.save(new PrintWriter(new FileOutputStream(f)));
Object[] saved = fileToStrings(f);
assertTrue(Arrays.equals(expected, saved));
Expand Down Expand Up @@ -202,7 +203,7 @@ public void testSetOptionFormat() throws IOException {
IniEditor.Section s = new IniEditor.Section("test");
s.setOptionFormatString(formats[i]);
s.set("hallo", "velo");
File f = File.createTempFile("test", null);
File f = Files.createTempFile("test", null).toFile();
s.save(new PrintWriter(new FileOutputStream(f)));
Object[] saved = fileToStrings(f);
assertEquals(expected[i], saved[0]);
Expand Down Expand Up @@ -231,7 +232,7 @@ private static Object[] fileToStrings(File f) throws IOException {
}

private static File toTempFile(String text) throws IOException {
File temp = File.createTempFile("inieditortest", null);
File temp = Files.createTempFile("inieditortest", null).toFile();
FileWriter fw = new FileWriter(temp);
fw.write(text);
fw.close();
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/aliyun/oss/integrationtests/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -395,7 +396,7 @@ public static boolean compareFileWithRange(String fileNameLeft, long start, long
}

public static File createSampleFile(String fileName, long size) throws IOException {
File file = File.createTempFile(fileName, ".txt");
File file = Files.createTempFile(fileName, ".txt").toFile();
file.deleteOnExit();
String context = "abcdefghijklmnopqrstuvwxyz0123456789011234567890\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -138,7 +139,7 @@ public void run() {
}

private File createSampleFile(String fileName, long size) throws IOException {
File file = File.createTempFile(fileName, ".txt");
File file = Files.createTempFile(fileName, ".txt").toFile();
file.deleteOnExit();
String context = "abcdefghijklmnopqrstuvwxyz0123456789011234567890\n";

Expand Down