Skip to content

Commit ab3be16

Browse files
First wave of security fixes
Issue: 102725
1 parent 29a2528 commit ab3be16

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

common/src/main/java/com/genexus/GXParameterUnpacker.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,8 @@ public final String readBlobfile()
477477
for (int i = data.length - 1; i >=0 ; i--)
478478
data[i] = readByte();
479479

480-
try
481-
{
482-
File file = new File(fileName);
483-
OutputStream destination = new BufferedOutputStream(new FileOutputStream(file));
480+
try (FileOutputStream fos = new FileOutputStream(new File(fileName))){
481+
OutputStream destination = new BufferedOutputStream(fos);
484482
destination.write(data, 0, data.length);
485483
destination.close();
486484
}

common/src/main/java/com/genexus/Messages.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ protected static final String getTab()
109109
private void load(String resourceName)
110110
{
111111
String line;
112-
InputStream is = null;
113-
try
112+
try (InputStream is = SpecificImplementation.Messages.getInputStream(resourceName);)
114113
{
115-
is = SpecificImplementation.Messages.getInputStream(resourceName);
116114

117115
if (is != null)
118116
{

common/src/main/java/com/genexus/util/PropertiesManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ public void flushProperties()
4444
for (Enumeration e = propertyFiles.keys(); e.hasMoreElements() ;)
4545
{
4646
String fileName = (String) e.nextElement();
47-
try
47+
try (FileOutputStream outputStream = new FileOutputStream(fileName);)
4848
{
49-
FileOutputStream outputStream = new FileOutputStream(fileName);
5049
((Properties) propertyFiles.get(fileName)).store(outputStream, "");
51-
outputStream.close();
5250
}
5351
catch (IOException ex)
5452
{

common/src/main/java/com/genexus/util/Template.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public static void main(String arg[])
1818
t.addPattern("ENABLE_CAB_IE" , "true");
1919
t.addPattern("IE_PLUGIN_URL" , "http://algo");
2020

21-
try
21+
try (FileReader fileReader = new FileReader("deployment.htm"); FileWriter fileWriter = new FileWriter("out.htm"))
2222
{
23-
t.applyTemplate(new BufferedReader(new FileReader("deployment.htm")), new BufferedWriter(new FileWriter("out.htm")));
23+
t.applyTemplate(new BufferedReader(fileReader), new BufferedWriter(fileWriter));
2424
}
2525
catch (IOException e)
2626
{

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.genexus.ws.rs.core.*;
1010
import org.apache.commons.io.FilenameUtils;
1111

12+
import java.io.InputStream;
13+
1214

1315
public class GXObjectUploadServices extends GXWebObjectStub
1416
{
@@ -87,24 +89,26 @@ protected void doExecute(HttpContext context) throws Exception
8789
fileName = com.genexus.PrivateUtilities.getTempFileName("", fName, "tmp");
8890
String filePath = fileDirPath + fileName;
8991
fileName = fileName.replaceAll(".tmp", "." + ext);
90-
FileItem fileItem = new FileItem(filePath, false, "", context.getRequest().getInputStream().getInputStream());
91-
savedFileName = fileItem.getPath();
92-
JSONObject jObj = new JSONObject();
93-
jObj.put("object_id", HttpUtils.getUploadFileId(keyId));
94-
if (!isRestCall) {
95-
context.getResponse().setContentType("application/json");
96-
context.getResponse().setStatus(201);
97-
context.getResponse().setHeader("GeneXus-Object-Id", keyId);
98-
((HttpContextWeb) context).writeText(jObj.toString());
99-
context.getResponse().flushBuffer();
100-
}
101-
else {
102-
String jsonResponse = jObj.toString();
103-
builder = Response.statusWrapped(201).entityWrapped(jsonResponse);
104-
builder.header("GeneXus-Object-Id", keyId);
105-
}
106-
if (!savedFileName.isEmpty()) {
107-
HttpUtils.CacheUploadFile(keyId, savedFileName, fileName, ext);
92+
try (InputStream is = context.getRequest().getInputStream().getInputStream()) {
93+
FileItem fileItem = new FileItem(filePath, false, "", is);
94+
savedFileName = fileItem.getPath();
95+
JSONObject jObj = new JSONObject();
96+
jObj.put("object_id", HttpUtils.getUploadFileId(keyId));
97+
if (!isRestCall) {
98+
context.getResponse().setContentType("application/json");
99+
context.getResponse().setStatus(201);
100+
context.getResponse().setHeader("GeneXus-Object-Id", keyId);
101+
((HttpContextWeb) context).writeText(jObj.toString());
102+
context.getResponse().flushBuffer();
103+
}
104+
else {
105+
String jsonResponse = jObj.toString();
106+
builder = Response.statusWrapped(201).entityWrapped(jsonResponse);
107+
builder.header("GeneXus-Object-Id", keyId);
108+
}
109+
if (!savedFileName.isEmpty()) {
110+
HttpUtils.CacheUploadFile(keyId, savedFileName, fileName, ext);
111+
}
108112
}
109113
}
110114
}

wrapperjakarta/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)