Skip to content

Commit b408f76

Browse files
committed
HADOOP-18235. vulnerability: we may leak sensitive information in LocalKeyStoreProvider
1 parent 4fe079f commit b408f76

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/LocalKeyStoreProvider.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,27 @@ protected void initFileSystem(URI uri)
142142

143143
@Override
144144
public void flush() throws IOException {
145-
super.flush();
146-
if (LOG.isDebugEnabled()) {
147-
LOG.debug("Resetting permissions to '" + permissions + "'");
148-
}
149-
if (!Shell.WINDOWS) {
150-
Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()),
151-
permissions);
152-
} else {
153-
// FsPermission expects a 10-character string because of the leading
154-
// directory indicator, i.e. "drwx------". The JDK toString method returns
155-
// a 9-character string, so prepend a leading character.
156-
FsPermission fsPermission = FsPermission.valueOf(
157-
"-" + PosixFilePermissions.toString(permissions));
158-
FileUtil.setPermission(file, fsPermission);
145+
try {
146+
super.getWriteLock().lock();
147+
file.createNewFile();
148+
if (LOG.isDebugEnabled()) {
149+
LOG.debug("Resetting permissions to '" + permissions + "'");
150+
}
151+
if (!Shell.WINDOWS) {
152+
Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()),
153+
permissions);
154+
} else {
155+
// FsPermission expects a 10-character string because of the leading
156+
// directory indicator, i.e. "drwx------". The JDK toString method returns
157+
// a 9-character string, so prepend a leading character.
158+
FsPermission fsPermission = FsPermission.valueOf(
159+
"-" + PosixFilePermissions.toString(permissions));
160+
FileUtil.setPermission(file, fsPermission);
161+
}
162+
} finally {
163+
super.getWriteLock().unlock();
159164
}
165+
super.flush();
160166
}
161167

162168
private static Set<PosixFilePermission> modeToPosixFilePermission(

0 commit comments

Comments
 (0)