Bound Telecom logging recursion

Put a bound on the recursion in Session#toString
to ensure we do not accidently cause a Stack overflow

Bug: 186694546
AOSP: aosp/1691210
Test: atest TeleServiceTests
Change-Id: I52f44dd02d0d860d0894e9b84fded8cf5ff5a18e
This commit is contained in:
Brad Ebinger
2021-04-29 13:59:16 -07:00
parent ce5f5faab8
commit bde5c37520

View File

@@ -453,19 +453,19 @@ public class Session {
@Override
public String toString() {
if (mParentSession != null && mIsStartedFromActiveSession) {
Session sessionToPrint = this;
if (getParentSession() != null && isStartedFromActiveSession()) {
// Log.startSession was called from within another active session. Use the parent's
// Id instead of the child to reduce confusion.
return mParentSession.toString();
} else {
StringBuilder methodName = new StringBuilder();
methodName.append(getFullMethodPath(false /*truncatePath*/));
if (mOwnerInfo != null && !mOwnerInfo.isEmpty()) {
methodName.append("(");
methodName.append(mOwnerInfo);
methodName.append(")");
}
return methodName.toString() + "@" + getFullSessionId();
sessionToPrint = getRootSession("toString");
}
StringBuilder methodName = new StringBuilder();
methodName.append(sessionToPrint.getFullMethodPath(false /*truncatePath*/));
if (sessionToPrint.getOwnerInfo() != null && !sessionToPrint.getOwnerInfo().isEmpty()) {
methodName.append("(");
methodName.append(sessionToPrint.getOwnerInfo());
methodName.append(")");
}
return methodName.toString() + "@" + sessionToPrint.getFullSessionId();
}
}