Skip to content

Commit 91e244d

Browse files
committed
detect dangerous/invalid chars in profiling directory name
1 parent 40c6756 commit 91e244d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

sentry-async-profiler/src/main/java/io/sentry/asyncprofiler/profiling/JavaContinuousProfiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private boolean isInvalidDirectory() {
122122
logger.log(
123123
SentryLevel.WARNING,
124124
"Disabling profiling because traces directory path contains invalid character: %s",
125-
filename);
125+
invalidChar);
126126
return true;
127127
}
128128
}

sentry-async-profiler/src/test/java/io/sentry/asyncprofiler/profiling/JavaContinuousProfilerTest.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class JavaContinuousProfilerTest {
8181
// Profiler doesn't start if the folder doesn't exists.
8282
// Usually it's generated when calling Sentry.init, but for tests we can create it manually.
8383

84-
fixture.options.cacheDirPath = "."
84+
fixture.options.cacheDirPath = "tmp"
8585
File(fixture.options.profilingTracesDirPath!!).mkdirs()
8686

8787
Sentry.setCurrentScopes(fixture.scopes)
@@ -406,6 +406,21 @@ class JavaContinuousProfilerTest {
406406
.log(eq(SentryLevel.WARNING), eq("SDK is rate limited. Stopping profiler."))
407407
}
408408

409+
@Test
410+
fun `profiler does not start when filename contains invalid characters`() {
411+
val profiler = fixture.getSut { it.profilingTracesDirPath = "," }
412+
413+
profiler.startProfiler(ProfileLifecycle.MANUAL, fixture.mockTracesSampler)
414+
assertFalse(profiler.isRunning)
415+
assertEquals(SentryId.EMPTY_ID, profiler.profilerId)
416+
verify(fixture.mockLogger)
417+
.log(
418+
eq(SentryLevel.WARNING),
419+
eq("Disabling profiling because traces directory path contains invalid character: %s"),
420+
eq(","),
421+
)
422+
}
423+
409424
fun withMockScopes(closure: () -> Unit) =
410425
Mockito.mockStatic(Sentry::class.java).use {
411426
it.`when`<Any> { Sentry.getCurrentScopes() }.thenReturn(fixture.scopes)

sentry/src/test/java/io/sentry/profiling/ProfilingServiceLoaderTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,8 @@ class ContinuousProfilerStub() : IContinuousProfiler {
7474
override fun getProfilerId(): SentryId {
7575
TODO("Not yet implemented")
7676
}
77+
78+
override fun getChunkId(): SentryId {
79+
TODO("Not yet implemented")
80+
}
7781
}

0 commit comments

Comments
 (0)