Skip to content

Commit ea5587e

Browse files
authored
launder and quote yet more paths (#4545)
1 parent 5a7e6c4 commit ea5587e

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/AbstractCache.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.history;
2424

@@ -72,7 +72,7 @@ File getCachedFile(File file) throws CacheException {
7272
}
7373
sb.append(add);
7474
} catch (ForbiddenSymlinkException | IOException e) {
75-
throw new CacheException("Failed to get path relative to source root for " + file, e);
75+
throw new CacheException(String.format("Failed to get path relative to source root for '%s'", file), e);
7676
}
7777

7878
String suffix = getCacheFileSuffix();
@@ -94,7 +94,7 @@ public List<String> clearCache(Collection<RepositoryInfo> repositories) {
9494
new Object[]{repo.getDirectoryName(), this.getInfo()});
9595
} catch (CacheException e) {
9696
LOGGER.log(Level.WARNING,
97-
"Clearing cache for repository {0} failed: {1}",
97+
"Clearing cache for repository ''{0}'' failed: {1}",
9898
new Object[]{repo.getDirectoryName(), e.getLocalizedMessage()});
9999
}
100100
}
@@ -110,11 +110,11 @@ static void clearWithParent(File file) {
110110
File parent = file.getParentFile();
111111

112112
if (!file.delete() && file.exists()) {
113-
LOGGER.log(Level.WARNING, "Failed to remove obsolete cache-file: {0}", file.getAbsolutePath());
113+
LOGGER.log(Level.WARNING, "Failed to remove obsolete cache-file: ''{0}''", file.getAbsolutePath());
114114
}
115115

116116
if (parent.delete()) {
117-
LOGGER.log(Level.FINE, "Removed empty cache dir:{0}", parent.getAbsolutePath());
117+
LOGGER.log(Level.FINE, "Removed empty cache dir: ''{0}''", parent.getAbsolutePath());
118118
}
119119
}
120120

opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryGuru.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ public String getAnnotationCacheInfo() {
236236
private Annotation getAnnotation(File file, @Nullable String rev, boolean fallback) throws IOException {
237237
Repository repository = getRepository(file);
238238
if (repository == null) {
239-
LOGGER.log(Level.FINER, "no repository found for ''{0}'' to check for annotation", file);
239+
LOGGER.finer(() -> String.format("no repository found for '%s' to check for annotation",
240+
launderLog(file.toString())));
240241
return null;
241242
}
242243

@@ -259,7 +260,7 @@ private Annotation getAnnotation(File file, @Nullable String rev, boolean fallba
259260
}
260261

261262
if (!HistoryGuru.getInstance().hasAnnotation(file)) {
262-
LOGGER.log(Level.FINER, "skipped getting annotation for file ''{0}}''", file);
263+
LOGGER.finer(() -> String.format("skipped getting annotation for file '%s'", launderLog(file.toString())));
263264
return null;
264265
}
265266

@@ -445,7 +446,8 @@ private HistoryEntry getLastHistoryEntryFromCache(File file, Repository reposito
445446
@Nullable
446447
public HistoryEntry getLastHistoryEntry(File file, boolean ui, boolean fallback) throws HistoryException {
447448
Statistics statistics = new Statistics();
448-
LOGGER.log(Level.FINEST, "started retrieval of last history entry for ''{0}''", file);
449+
LOGGER.finest(() -> String.format("started retrieval of last history entry for '%s'",
450+
launderLog(file.toString())));
449451
final File dir = file.isDirectory() ? file : file.getParentFile();
450452
final Repository repository = getRepository(dir);
451453
final String meterName = "history.entry.latest";
@@ -707,7 +709,7 @@ public boolean hasHistoryCacheForFile(File file) {
707709
*/
708710
public boolean hasAnnotation(File file, @Nullable Document document) {
709711
if (file.isDirectory()) {
710-
LOGGER.log(Level.FINEST, "no annotations for directories (''{0}'')", file);
712+
LOGGER.finest(() -> String.format("no annotations for directories: '%s'", launderLog(file.toString())));
711713
return false;
712714
}
713715

@@ -716,7 +718,8 @@ public boolean hasAnnotation(File file, @Nullable Document document) {
716718
// however it does not hurt to check in case this will change.
717719
String fileType = document.get(QueryBuilder.T);
718720
if (fileType == null || !isXrefable(fileType)) {
719-
LOGGER.log(Level.FINEST, "no file type found in document for ''{0}'' or not xref-able", file);
721+
LOGGER.finest(() -> String.format("no file type found in document for '%s' or not xref-able",
722+
launderLog(file.toString())));
720723
return false;
721724
}
722725
}

opengrok-indexer/src/main/java/org/opengrok/indexer/util/PathUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
/*
21+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2122
* Copyright (c) 2017, 2019, Chris Fraire <cfraire@me.com>.
2223
*/
2324
package org.opengrok.indexer.util;
@@ -139,7 +140,7 @@ public static String getRelativeToCanonical(Path path, Path canonical,
139140
if (Objects.nonNull(allowedSymlinks) && Files.isSymbolicLink(iterPath) &&
140141
!isWhitelisted(iterCanon.toString(), canonicalRoots) &&
141142
!isAllowedSymlink(iterCanon, allowedSymlinks)) {
142-
String format = String.format("%1$s is prohibited symlink", iterPath);
143+
String format = String.format("'%1$s' is prohibited symlink", iterPath);
143144
LOGGER.finest(format);
144145
throw new ForbiddenSymlinkException(format);
145146
}
@@ -180,8 +181,7 @@ private static boolean isAllowedSymlink(Path canonicalFile,
180181
canonicalLink = fileSystem.getPath(allowedSymlink).toRealPath().toString();
181182
} catch (IOException e) {
182183
if (LOGGER.isLoggable(Level.FINE)) {
183-
LOGGER.fine(String.format("unresolvable symlink: %s",
184-
allowedSymlink));
184+
LOGGER.fine(String.format("unresolvable symlink: '%s'", allowedSymlink));
185185
}
186186
continue;
187187
}

0 commit comments

Comments
 (0)