Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOGMGR-258] At non static points, invoke doPrivileged only if Securi… #268

Merged
merged 1 commit into from Jul 24, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -118,7 +118,8 @@ private LogContext check(final ClassLoader classLoader) {
*/
@Override
public LogContext getLogContext() {
return AccessController.doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
AccessController.doPrivileged(logContextAction);
}

/**
Expand Down
Expand Up @@ -118,7 +118,8 @@ private LogContext check(final ClassLoader classLoader) {
* with any log context.
*/
public LogContext getLogContext() {
return AccessController.doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
AccessController.doPrivileged(logContextAction);
}

/**
Expand Down
Expand Up @@ -69,7 +69,8 @@ public LogContext run() {
};

public LogContext getLogContext() {
return doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
doPrivileged(logContextAction);
}

/**
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/org/jboss/logmanager/formatters/Formatters.java
Expand Up @@ -765,26 +765,33 @@ public static FormatStep exceptionFormatStep(final boolean leftJustify, final in
public static FormatStep exceptionFormatStep(final boolean leftJustify, final int minimumWidth, final boolean truncateBeginning, final int maximumWidth, final String argument, final boolean extended) {
return new JustifyingFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth) {
public void renderRaw(final StringBuilder builder, final ExtLogRecord record) {
doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
final Throwable t = record.getThrown();
if (t != null) {
int depth = -1;
if (argument != null) {
try {
depth = Integer.parseInt(argument);
} catch (NumberFormatException ignore) {
}
}
StackTraceFormatter.renderStackTrace(builder, t, extended, depth);
if (System.getSecurityManager() != null)
doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
doExceptionFormatStep(builder, record, argument, extended);
return null;
}
return null;
}
});
});
else
doExceptionFormatStep(builder, record, argument, extended);
}
};
}

private static void doExceptionFormatStep(final StringBuilder builder, final ExtLogRecord record, final String argument, final boolean extended) {
final Throwable t = record.getThrown();
if (t != null) {
int depth = -1;
if (argument != null) {
try {
depth = Integer.parseInt(argument);
} catch (NumberFormatException ignore) {
}
}
StackTraceFormatter.renderStackTrace(builder, t, extended, depth);
}
}

/**
* Create a format step which emits the log message resource key (if any) with the given justification rules.
*
Expand Down