Skip to content

Commit fb8e75f

Browse files
committed
fix: decode native executable path without buffer mutation
1 parent 84bec7d commit fb8e75f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • ktor-client-curl-android-native/src/androidNativeArm64Main/kotlin/io/ktor/client/engine/curl

ktor-client-curl-android-native/src/androidNativeArm64Main/kotlin/io/ktor/client/engine/curl/AndroidNativeCurlCa.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import kotlinx.cinterop.addressOf
88
import kotlinx.cinterop.allocArray
99
import kotlinx.cinterop.convert
1010
import kotlinx.cinterop.memScoped
11+
import kotlinx.cinterop.readBytes
1112
import kotlinx.cinterop.toKString
1213
import kotlinx.cinterop.usePinned
1314
import platform.posix.F_OK
@@ -65,6 +66,5 @@ private fun currentProgramDirectory(): String? = memScoped {
6566
val buffer = allocArray<ByteVar>(bufferSize)
6667
val length = readlink("/proc/self/exe", buffer, (bufferSize - 1).convert())
6768
if (length <= 0) return@memScoped null
68-
buffer[length] = 0
69-
buffer.toKString().substringBeforeLast('/', "").ifBlank { null }
69+
buffer.readBytes(length.toInt()).decodeToString().substringBeforeLast('/', "").ifBlank { null }
7070
}

0 commit comments

Comments
 (0)