Skip to content
Merged
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
20 changes: 16 additions & 4 deletions common/src/main/java/com/genexus/util/GXFileInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
public class GXFileInfo implements IGXFileInfo {

private File fileSource;
private ClassPathResource resource;
private boolean isDirectory;

public GXFileInfo(File file){
this(file, false);
}
public GXFileInfo(File file, boolean isDirectory){
if (ApplicationContext.getInstance().isSpringBootApp() && ! file.exists() && !file.getPath().equals(""))
resource = new ClassPathResource(file.getPath());
fileSource = file;
this.isDirectory = isDirectory;
}
Expand All @@ -36,8 +39,8 @@ public String getPath(){
}
}
public boolean exists(){
if (ApplicationContext.getInstance().isSpringBootApp() && !isDirectory) {
if (!fileSource.exists() && !new ClassPathResource(fileSource.getPath()).exists())
if (resource != null && !isDirectory) {
if (!fileSource.exists() && !resource.exists())
return false;
return true;
}
Expand All @@ -48,6 +51,8 @@ public boolean exists(){
return false;
}
public boolean isFile(){
if (resource != null)
return true;
return fileSource.isFile();
}
public boolean isDirectory(){
Expand Down Expand Up @@ -88,6 +93,13 @@ public String getAbsolutePath(){
return fileSource.getAbsolutePath();
}
public long length(){
if (resource != null && !fileSource.exists())
try {
return resource.contentLength();
}
catch (IOException _) {
return 0;
}
return fileSource.length();
}
public Date lastModified(){
Expand Down Expand Up @@ -139,8 +151,8 @@ public GXDirectoryCollection listDirectories(){

public InputStream getStream(){
try {
if (ApplicationContext.getInstance().isSpringBootApp()) {
return new ClassPathResource(fileSource.getPath()).getInputStream();
if (resource != null && !fileSource.exists()) {
return resource.getInputStream();
}

return new FileInputStream(fileSource);
Expand Down
29 changes: 29 additions & 0 deletions gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
package com.genexus.springboot;

import com.genexus.Application;
import com.genexus.common.interfaces.SpecificImplementation;
import com.genexus.diagnostics.core.ILogger;
import com.genexus.diagnostics.core.LogManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

@Configuration
@EnableWebMvc
public class GXConfig implements WebMvcConfigurer {
public static final ILogger logger = LogManager.getLogger(GXConfig.class);

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
AntPathMatcher matcher = new AntPathMatcher();
matcher.setCaseSensitive(false);
configurer.setPathMatcher(matcher);
}

@Value("${server.servlet.context-parameters.gxcfg}")
private String gxConfig;

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
try {
Application.init(Class.forName(gxConfig));

String webImageDir = Application.getClientContext().getClientPreferences().getWEB_IMAGE_DIR();
String blobPath = SpecificImplementation.Application.getDefaultPreferences().getBLOB_PATH().replace("\\", "");

registry.addResourceHandler(webImageDir + "**")
.addResourceLocations("classpath:" + webImageDir);

registry.addResourceHandler("/" + blobPath + "/**")
.addResourceLocations("file:./" + blobPath + "/");
}
catch (ClassNotFoundException e) {
logger.error("Error setting context folders ", e);
}
}
}
24 changes: 14 additions & 10 deletions java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -1414,7 +1411,13 @@ public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws
if(webContext != null)
{
if (webContext instanceof com.genexus.webpanels.HttpContextWeb) {
fileName = ((com.genexus.webpanels.HttpContextWeb) webContext).getRealPath(fileName);
if (ApplicationContext.getInstance().isSpringBootApp() && ! new File(fileName).isAbsolute())
{
if (fileName.startsWith(webContext.getContextPath()))
fileName = fileName.replaceFirst(webContext.getContextPath(), "").substring(1);

Check failure

Code scanning / CodeQL

Regular expression injection

This regular expression is constructed from a [user-provided value](1).
}
else
fileName = ((com.genexus.webpanels.HttpContextWeb) webContext).getRealPath(fileName);
}
else
{
Expand Down Expand Up @@ -1452,16 +1455,17 @@ else if(blobFiles.length < index)
{
if (Application.getExternalProvider() == null)
{
try
GXFile file = new GXFile(fileName);
InputStream is = file.getStream();
if (is != null)
{
File file = new File(fileName);
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
setBinaryStream(index, inputStream, (int) file.length());
BufferedInputStream inputStream = new BufferedInputStream(is);
setBinaryStream(index, inputStream, (int) file.getLength());
}
catch (IOException e)
else
{
throw new SQLException("The filename does not exists in url " + fileName);
}
}
}
else
{
Expand Down
16 changes: 13 additions & 3 deletions java/src/main/java/com/genexus/webpanels/HttpContextWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public String getResourceRelative(String path, boolean includeBasePath) {
}
;
String Resource = path;
String basePath = getDefaultPath();
String basePath = getDefaultPath(true);
if (Resource.startsWith(basePath) && Resource.length() >= basePath.length())
Resource = Resource.substring(basePath.length());
if (ContextPath != null && !ContextPath.equals("") && Resource.startsWith(ContextPath))
Expand Down Expand Up @@ -516,6 +516,9 @@ public String getContextPath() {
public void setContextPath(String path) {}

public String getRealPath(String path) {
if (ApplicationContext.getInstance().isSpringBootApp())
return path;

String realPath = path;

File file = new File(path);
Expand Down Expand Up @@ -1255,8 +1258,15 @@ private boolean useCustomRedirect() {
}

public String getDefaultPath() {
if (ApplicationContext.getInstance().isSpringBootApp())
return "";
return getDefaultPath(false);
}
public String getDefaultPath(boolean useAbsolutePath) {
if (ApplicationContext.getInstance().isSpringBootApp()) {
if (useAbsolutePath)
return new File("").getAbsolutePath();
else
return "";
}

if (servletContext == null)
return "";
Expand Down