Skip to content

Commit

Permalink
launder and quote yet more paths (oracle#4545)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak authored Feb 19, 2024
1 parent 5a7e6c4 commit ea5587e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.history;

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

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

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

if (parent.delete()) {
LOGGER.log(Level.FINE, "Removed empty cache dir:{0}", parent.getAbsolutePath());
LOGGER.log(Level.FINE, "Removed empty cache dir: ''{0}''", parent.getAbsolutePath());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ public String getAnnotationCacheInfo() {
private Annotation getAnnotation(File file, @Nullable String rev, boolean fallback) throws IOException {
Repository repository = getRepository(file);
if (repository == null) {
LOGGER.log(Level.FINER, "no repository found for ''{0}'' to check for annotation", file);
LOGGER.finer(() -> String.format("no repository found for '%s' to check for annotation",
launderLog(file.toString())));
return null;
}

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

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

Expand Down Expand Up @@ -445,7 +446,8 @@ private HistoryEntry getLastHistoryEntryFromCache(File file, Repository reposito
@Nullable
public HistoryEntry getLastHistoryEntry(File file, boolean ui, boolean fallback) throws HistoryException {
Statistics statistics = new Statistics();
LOGGER.log(Level.FINEST, "started retrieval of last history entry for ''{0}''", file);
LOGGER.finest(() -> String.format("started retrieval of last history entry for '%s'",
launderLog(file.toString())));
final File dir = file.isDirectory() ? file : file.getParentFile();
final Repository repository = getRepository(dir);
final String meterName = "history.entry.latest";
Expand Down Expand Up @@ -707,7 +709,7 @@ public boolean hasHistoryCacheForFile(File file) {
*/
public boolean hasAnnotation(File file, @Nullable Document document) {
if (file.isDirectory()) {
LOGGER.log(Level.FINEST, "no annotations for directories (''{0}'')", file);
LOGGER.finest(() -> String.format("no annotations for directories: '%s'", launderLog(file.toString())));
return false;
}

Expand All @@ -716,7 +718,8 @@ public boolean hasAnnotation(File file, @Nullable Document document) {
// however it does not hurt to check in case this will change.
String fileType = document.get(QueryBuilder.T);
if (fileType == null || !isXrefable(fileType)) {
LOGGER.log(Level.FINEST, "no file type found in document for ''{0}'' or not xref-able", file);
LOGGER.finest(() -> String.format("no file type found in document for '%s' or not xref-able",
launderLog(file.toString())));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.util;
Expand Down Expand Up @@ -139,7 +140,7 @@ public static String getRelativeToCanonical(Path path, Path canonical,
if (Objects.nonNull(allowedSymlinks) && Files.isSymbolicLink(iterPath) &&
!isWhitelisted(iterCanon.toString(), canonicalRoots) &&
!isAllowedSymlink(iterCanon, allowedSymlinks)) {
String format = String.format("%1$s is prohibited symlink", iterPath);
String format = String.format("'%1$s' is prohibited symlink", iterPath);
LOGGER.finest(format);
throw new ForbiddenSymlinkException(format);
}
Expand Down Expand Up @@ -180,8 +181,7 @@ private static boolean isAllowedSymlink(Path canonicalFile,
canonicalLink = fileSystem.getPath(allowedSymlink).toRealPath().toString();
} catch (IOException e) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.format("unresolvable symlink: %s",
allowedSymlink));
LOGGER.fine(String.format("unresolvable symlink: '%s'", allowedSymlink));
}
continue;
}
Expand Down

0 comments on commit ea5587e

Please sign in to comment.