Skip to content

Commit 6612631

Browse files
Thrid wave of security fixes
Fixes 225, 224, 223, 221, 220, 219, 218, 217, 216, 215, 214 and 213
1 parent cc2e8d2 commit 6612631

File tree

10 files changed

+53
-46
lines changed

10 files changed

+53
-46
lines changed

common/src/main/java/HTTPClient/FileConnection.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ public InputStream getInputStream()throws IOException
8484
public synchronized byte [] getData() throws IOException
8585
{
8686
if(Data != null)return Data;
87-
Data = new byte[(int)size];
87+
Data = new byte[(int)size];
8888
if(inp == null)
89-
getInputStream().read(Data);
90-
getInputStream().close();
89+
try {
90+
getInputStream().read(Data);
91+
} finally {
92+
getInputStream().close();
93+
}
9194
return Data;
9295
}
9396

common/src/main/java/com/genexus/reports/ParseINI.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ public ParseINI(String filename, String configurationTemplateFile) throws IOExc
7575

7676
private void init(String filename) throws IOException{
7777
this.filename = new File(filename).getAbsolutePath();
78-
try
78+
try (FileInputStream inputStream = new FileInputStream(filename);)
7979
{
80-
FileInputStream inputStream = new FileInputStream(filename);
8180
load(inputStream);
82-
inputStream.close();
8381
}
8482
catch(FileNotFoundException fnfe)
8583
{ // Si debo crear el archivo

common/src/main/java/com/genexus/xml/XMLReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,12 +834,12 @@ public void openFromString(String s)
834834
public void openResponse(com.genexus.internet.HttpClient client)
835835
{
836836
reset();
837-
try
837+
try (InputStream is = client.getInputStream())
838838
{
839839
if (documentEncoding.length() > 0)
840-
inputSource = new XMLInputSource(null, null, null, client.getInputStream(), documentEncoding);
840+
inputSource = new XMLInputSource(null, null, null, is, documentEncoding);
841841
else
842-
inputSource = new XMLInputSource(null, null, null, client.getInputStream(), null);
842+
inputSource = new XMLInputSource(null, null, null, is, null);
843843
parserConfiguration.setInputSource(inputSource);
844844
}
845845
catch (IOException e)

gxmail/src/main/java/com/genexus/internet/MailMessage.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,27 +174,31 @@ private void readBody(MailReader reader, MailProperties partProps, String separa
174174

175175
String oldSeparator = reader.getSeparator();
176176
reader.setSeparator(separator);
177-
OutputStream out;
178-
179-
if (isAttachment)
180-
{
181-
if (this.downloadAttachments){
182-
String name = partProps.getKeyProperty(GXInternetConstants.CONTENT_TYPE, GXInternetConstants.NAME);
183-
String fileName = partProps.getKeyProperty(GXInternetConstants.CONTENT_DISPOSITION, GXInternetConstants.FILENAME);
184-
String outname = getFileName(attachmentsPath, fileName.length() == 0?name:fileName, partProps.getMimeMediaSubtype());
185-
186-
attachments += outname + ";";
187-
out = new FileOutputStream(attachmentsPath + outname);
177+
OutputStream out = null;
178+
179+
try{
180+
if (isAttachment)
181+
{
182+
if (this.downloadAttachments){
183+
String name = partProps.getKeyProperty(GXInternetConstants.CONTENT_TYPE, GXInternetConstants.NAME);
184+
String fileName = partProps.getKeyProperty(GXInternetConstants.CONTENT_DISPOSITION, GXInternetConstants.FILENAME);
185+
String outname = getFileName(attachmentsPath, fileName.length() == 0?name:fileName, partProps.getMimeMediaSubtype());
186+
187+
attachments += outname + ";";
188+
out = new FileOutputStream(attachmentsPath + outname);
189+
}
190+
else
191+
{
192+
out = new DummyOutputStream();
193+
}
194+
188195
}
189-
else
196+
else
190197
{
191-
out = new DummyOutputStream();
198+
out = new ByteArrayOutputStream();
192199
}
193-
194-
}
195-
else
196-
{
197-
out = new ByteArrayOutputStream();
200+
} finally {
201+
if (out == null) out.close();
198202
}
199203

200204
getDecoder(partProps.getField(GXInternetConstants.CONTENT_TRANSFER_ENCODING)).decode(reader, out);

gxmail/src/main/java/com/genexus/internet/SMTPSession.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,20 +613,23 @@ private String getNextMessage(String sTime, String sPrefix, boolean end)
613613

614614
private void sendAttachment(String sTime, String fileNamePath, String attachmentPath) throws GXMailException, IOException
615615
{
616-
InputStream is;
616+
InputStream is = null;
617617
String fileName = fileNamePath;
618618

619619
if (fileNamePath.lastIndexOf(File.separator) != -1)
620620
fileName = fileNamePath.substring(fileNamePath.lastIndexOf(File.separator) + 1);
621621

622-
try
623-
{
622+
try {
624623
is = new FileInputStream(attachmentPath + fileNamePath);
625624
}
626-
catch (FileNotFoundException e)
627-
{
625+
catch (FileNotFoundException e) {
628626
log ("11 - FileNotFound " + e.getMessage());
629627
throw new GXMailException("Can't find " + attachmentPath + fileNamePath, MAIL_InvalidAttachment);
628+
} finally {
629+
if (is == null) {
630+
log ("SMTPSession.java failed to open an output stream for the file");
631+
throw new GXMailException("Can't find " + attachmentPath + fileNamePath, MAIL_InvalidAttachment);
632+
}
630633
}
631634

632635
println(getNextMessageIdMixed(sTime, false));

gxoffice/src/main/java/com/genexus/gxoffice/poi/hssf/ExcelDocument.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.genexus.util.GXFile;
1212
import java.io.ByteArrayInputStream;
1313
import java.io.ByteArrayOutputStream;
14-
14+
import java.io.InputStream;
1515

1616

1717
/**
@@ -53,9 +53,10 @@ public short Open(String fileName)
5353
boolean isAbsolute = new java.io.File(fileName).isAbsolute();
5454
GXFile file = new GXFile(fileName, Constants.EXTERNAL_UPLOAD_ACL, isAbsolute);
5555
if (file.exists()) {
56-
//System.out.println("Opening..");
57-
POIFSFileSystem poifs = new POIFSFileSystem(file.getStream());
58-
workBook = new HSSFWorkbook(poifs);
56+
try (InputStream is = file.getStream()) {
57+
POIFSFileSystem poifs = new POIFSFileSystem(is);
58+
workBook = new HSSFWorkbook(poifs);
59+
}
5960
}
6061
else {
6162
//System.out.println("Creating..");

gxsearch/src/main/java/com/genexus/search/TextHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ public class TextHandler implements IDocumentHandler
66
{
77
public String getText(String filename)
88
{
9-
try
9+
try (FileReader rd = new FileReader(filename))
1010
{
1111
File f = new File(filename);
12-
FileReader rd = new FileReader(f);
1312
char[] buf = new char[(int)f.length()];
1413
rd.read(buf);
1514
rd.close();

java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,9 @@ public void setBLOBFile(java.sql.Blob blob, String fileName) throws SQLException
13421342
{
13431343
if(con.getDBMS().getId() == GXDBMS.DBMS_ORACLE || con.getDBMS().getId() == GXDBMS.DBMS_DAMENG)
13441344
{
1345-
try
1345+
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(fileName)))
13461346
{
13471347
File file = new File(fileName);
1348-
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
13491348
if(con.getDBMS().getId() == GXDBMS.DBMS_ORACLE)
13501349
((GXDBMSoracle7)con.getDBMS()).setBlobData(blob, inputStream, (int) file.length());
13511350
else

java/src/main/java/com/genexus/db/driver/GXResultSet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,9 @@ public String getBLOBFile(int columnIndex, String extension, String name) throws
935935

936936
private String getBLOBFile(int columnIndex, String extension, String name, String fileName, boolean temporary) throws SQLException
937937
{
938-
try
938+
try (InputStream source = getBinaryStream(columnIndex);)
939939
{
940-
InputStream source = getBinaryStream(columnIndex);
940+
941941

942942
byte[] xbuffer = new byte[1];
943943
int firstByte = 0;

java/src/main/java/com/genexus/internet/NetComponentsFTPClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ public int get(String source, String target, String mode)
141141
if (ftp.isConnected())
142142
{
143143
target = normalizeName(source, target, '/', File.separatorChar);
144-
try
144+
try (FileOutputStream targetOutputStream = new FileOutputStream(target))
145145
{
146146
setFileType(mode);
147147

148-
OutputStream o = new BufferedOutputStream(new FileOutputStream(target));
148+
OutputStream o = new BufferedOutputStream(targetOutputStream);
149149
if (ftp.retrieveFile(source, o))
150150
{
151151
o.close();
@@ -192,10 +192,10 @@ public int put(String source, String target, String mode)
192192
if (ftp.isConnected())
193193
{
194194
target = normalizeName(source, target, File.separatorChar, '/');
195-
try
195+
try (FileInputStream fileInputStream = new FileInputStream(source))
196196
{
197197
setFileType(mode);
198-
InputStream file = new BufferedInputStream(new FileInputStream(source));
198+
InputStream file = new BufferedInputStream(fileInputStream);
199199

200200
if (ftp.storeFile(target, file))
201201
{

0 commit comments

Comments
 (0)