Skip to content

Commit 8cd3611

Browse files
Second wave of security fixes
Alerts 236, 235, 234, 233, 231, 230, 229, 228, 227 and 226
1 parent ab3be16 commit 8cd3611

File tree

10 files changed

+46
-37
lines changed

10 files changed

+46
-37
lines changed

android/src/main/java/com/genexus/PrivateUtilities.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,9 @@ class ReadProperties implements Runnable
10041004

10051005
public void run()
10061006
{
1007-
try
1007+
try (FileInputStream in = new FileInputStream(fileName);)
10081008
{
1009-
FileInputStream in = new FileInputStream(fileName);
10101009
props.load(new BufferedInputStream(in));
1011-
in.close();
10121010
}
10131011
catch (IOException e)
10141012
{

common/src/main/java/com/genexus/diagnostics/GXDebugManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,9 @@ class ESCAPE
565565

566566
static GXDebugStream getStream(String fileName) throws IOException
567567
{
568-
FileOutputStream stream = new FileOutputStream(fileName, true);
569-
return new GXDebugStream(new BufferedOutputStream(stream), stream.getChannel());
568+
try (FileOutputStream stream = new FileOutputStream(fileName, true)){
569+
return new GXDebugStream(new BufferedOutputStream(stream), stream.getChannel());
570+
}
570571
}
571572

572573
private GXDebugStream(OutputStream stream, FileChannel channel) throws IOException

gxoffice/src/main/java/com/genexus/gxoffice/ExcelDoc.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ public void checkExcelDocument() {
8686
}
8787

8888
private boolean isXlsx(String fileName) throws Throwable {
89-
try {
90-
GXFile file = new GXFile(fileName);
91-
java.io.InputStream is = new BufferedInputStream(file.getStream());
89+
try (java.io.InputStream is = new BufferedInputStream(new GXFile(fileName).getStream());) {
9290
boolean isXlsx = FileMagic.valueOf(is) == FileMagic.OOXML;
9391
is.close();
9492
return isXlsx;

gxoffice/src/main/java/com/genexus/msoffice/excel/poi/xssf/ExcelSpreadsheet.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.ByteArrayInputStream;
44
import java.io.ByteArrayOutputStream;
55
import java.io.IOException;
6+
import java.io.InputStream;
67
import java.util.ArrayList;
78
import java.util.List;
89

@@ -44,21 +45,25 @@ public ExcelSpreadsheet(IGXError errHandler, String fileName, String template) t
4445
fileName += ".xlsx";
4546
}
4647

47-
if (!template.equals("")) {
48-
GXFile templateFile = new GXFile(template);
49-
if (templateFile.exists()) {
50-
_workbook = new XSSFWorkbook(templateFile.getStream());
51-
} else {
52-
throw new ExcelTemplateNotFoundException();
53-
}
54-
} else {
55-
GXFile file = new GXFile(fileName, Constants.EXTERNAL_PRIVATE_UPLOAD);
56-
if (file.exists()) {
57-
_workbook = new XSSFWorkbook(file.getStream());
48+
InputStream is = null;
49+
try {
50+
if (!template.equals("")) {
51+
GXFile templateFile = new GXFile(template);
52+
if (templateFile.exists()) {
53+
is = templateFile.getStream();
54+
_workbook = new XSSFWorkbook();
55+
} else {
56+
throw new ExcelTemplateNotFoundException();
57+
}
5858
} else {
59-
_workbook = new XSSFWorkbook();
59+
GXFile file = new GXFile(fileName, Constants.EXTERNAL_PRIVATE_UPLOAD);
60+
if (file.exists()) {
61+
_workbook = new XSSFWorkbook(file.getStream());
62+
} else {
63+
_workbook = new XSSFWorkbook();
64+
}
6065
}
61-
}
66+
} finally { if (is != null) is.close(); }
6267

6368
_documentFileName = fileName;
6469

java/src/main/java/com/genexus/PrivateUtilities.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,11 +1216,9 @@ class ReadProperties implements Runnable
12161216

12171217
public void run()
12181218
{
1219-
try
1219+
try (FileInputStream in = new FileInputStream(fileName);)
12201220
{
1221-
FileInputStream in = new FileInputStream(fileName);
12221221
props.load(new BufferedInputStream(in));
1223-
in.close();
12241222
}
12251223
catch (IOException e)
12261224
{

java/src/main/java/com/genexus/Version.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.genexus;
22

33
import org.apache.logging.log4j.Logger;
4+
5+
import java.io.IOException;
46
import java.util.jar.*;
57

68
public class Version
@@ -10,16 +12,19 @@ public class Version
1012
public static final String getFullVersion()
1113
{
1214
String version = "";
15+
JarInputStream jarStream = null;
1316
try {
1417
String path = com.genexus.Application.class.getProtectionDomain().getCodeSource().getLocation().getPath();
1518
String decodedPath = java.net.URLDecoder.decode(path, "UTF-8");
16-
JarInputStream jarStream = new JarInputStream(new java.io.FileInputStream(decodedPath));
19+
jarStream = new JarInputStream(new java.io.FileInputStream(decodedPath));
1720
Manifest mf = jarStream.getManifest();
1821
Attributes attributes = mf.getMainAttributes();
1922
version = attributes.getValue("Build-Label");
2023
}
2124
catch (Exception e) {
2225
log.debug("Could not get Build-Label information");
26+
} finally {
27+
try{ if (jarStream != null) jarStream.close(); } catch (IOException ioe) { log.debug("Could not close jar input stream"); }
2328
}
2429

2530
return version;

java/src/main/java/com/genexus/reports/GXReportText.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,9 @@ public void close()
158158
}
159159
else
160160
{
161-
try
161+
try (FileInputStream fInput = new FileInputStream(fileName))
162162
{
163163
PrintService ps = getDefaultPrinter();
164-
FileInputStream fInput = new FileInputStream(fileName);
165164
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
166165
DocPrintJob pj = ps.createPrintJob();
167166
Doc doc = new SimpleDoc(fInput, flavor, null);
@@ -174,7 +173,11 @@ public void close()
174173
catch (PrintException e)
175174
{
176175
System.out.println("Error printing report " + fileName + " " + e.getMessage());
177-
}
176+
}
177+
catch (IOException ioe)
178+
{
179+
System.out.println("Error opening file input stream of file " + fileName + " " + ioe.getMessage());
180+
}
178181
}
179182
}
180183
}

java/src/main/java/com/genexus/specific/java/HttpClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.genexus.specific.java;
22

3+
import java.io.InputStream;
34
import java.util.Hashtable;
45

56
import com.genexus.CommonUtil;
67
import com.genexus.common.interfaces.IExtensionHttpClient;
78
import com.genexus.common.interfaces.SpecificImplementation;
89
import com.genexus.internet.HttpClientJavaLib;
910
import com.genexus.internet.HttpClientManual;
11+
import com.genexus.util.Base64;
1012

1113
import javax.net.ssl.SSLSocket;
1214

@@ -48,9 +50,9 @@ private com.genexus.internet.IHttpClient useHttpClientOldImplementation() {
4850
@Override
4951
public com.genexus.internet.IHttpClient initHttpClientImpl() {
5052
com.genexus.internet.IHttpClient client = null;
51-
try {
53+
try (InputStream is = com.genexus.ResourceReader.getResourceAsStream("useoldhttpclient.txt")){
5254

53-
if (com.genexus.ResourceReader.getResourceAsStream("useoldhttpclient.txt") == null) {
55+
if (is == null) {
5456
Class.forName("org.apache.http.impl.conn.PoolingHttpClientConnectionManager"); // httpclient-4.5.14.jar dectected by reflection
5557
client = new HttpClientJavaLib();
5658
} else

java/src/main/java/com/genexus/webpanels/WebUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,8 @@ private static InputStream getInputStreamFile(Class<?> gxAppClass, String fileNa
444444

445445
public static void getGXApplicationClasses(Class<?> gxAppClass, Set<Class<?>> rrcs)
446446
{
447-
try
447+
try (InputStream is = getInputStreamFile(gxAppClass, gxApplicationClassesFileName);)
448448
{
449-
InputStream is = getInputStreamFile(gxAppClass, gxApplicationClassesFileName);
450449
BufferedReader input = new BufferedReader(new InputStreamReader(is, "UTF8"));
451450
String restClass = input.readLine();
452451
while (restClass != null)

wrapperjavax/src/main/java/com/genexus/ws/RestReaderInterceptor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class RestReaderInterceptor implements ReaderInterceptor {
1313

1414
@Override
1515
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
16-
InputStream is = context.getInputStream();
16+
try (InputStream is = context.getInputStream()){
17+
InputStream isBody = com.genexus.WrapperUtils.storeRestRequestBody(is);
1718

18-
InputStream isBody = com.genexus.WrapperUtils.storeRestRequestBody(is);
19-
20-
context.setInputStream(isBody);
21-
return context.proceed();
19+
context.setInputStream(isBody);
20+
return context.proceed();
21+
}
2222
}
2323
}

0 commit comments

Comments
 (0)