Skip to content

Commit 4ad149e

Browse files
committed
Protect against bad paths and URLs
See gh-21722
1 parent 88e9f1d commit 4ad149e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackReference.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ Path asPath() {
5353
if (url.getProtocol().equals("file")) {
5454
return Paths.get(url.getPath());
5555
}
56+
return null;
5657
}
5758
catch (MalformedURLException ex) {
5859
// not a URL, fall through to attempting to find a plain file path
5960
}
60-
return Paths.get(this.value);
61+
try {
62+
return Paths.get(this.value);
63+
}
64+
catch (Exception ex) {
65+
return null;
66+
}
6167
}
6268

6369
@Override

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private void addLayerContent(Layout layout) throws IOException {
9393
*/
9494
static Buildpack resolve(BuildpackResolverContext context, BuildpackReference reference) {
9595
Path path = reference.asPath();
96-
if (Files.exists(path) && Files.isDirectory(path)) {
96+
if (path != null && Files.exists(path) && Files.isDirectory(path)) {
9797
return new DirectoryBuildpack(path);
9898
}
9999
return null;

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/TarGzipBuildpack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void copyAndRebaseEntries(OutputStream outputStream) throws IOException
109109
*/
110110
static Buildpack resolve(BuildpackResolverContext context, BuildpackReference reference) {
111111
Path path = reference.asPath();
112-
if (Files.exists(path) && Files.isRegularFile(path)) {
112+
if (path != null && Files.exists(path) && Files.isRegularFile(path)) {
113113
return new TarGzipBuildpack(path);
114114
}
115115
return null;

0 commit comments

Comments
 (0)