Check for nil in cstringArrayToSeq (#23747)

This fixes crashes in some specific network configurations (as
`cstringArrayToSeq` is used extensively in `nativesockets`).

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
Yuriy Glukhov
2024-06-24 09:35:05 +02:00
committed by GitHub
parent 832d896cda
commit 2c83f94544

View File

@@ -2102,12 +2102,14 @@ when not defined(js):
proc cstringArrayToSeq*(a: cstringArray, len: Natural): seq[string] =
## Converts a `cstringArray` to a `seq[string]`. `a` is supposed to be
## of length `len`.
if a == nil: return @[]
newSeq(result, len)
for i in 0..len-1: result[i] = $a[i]
proc cstringArrayToSeq*(a: cstringArray): seq[string] =
## Converts a `cstringArray` to a `seq[string]`. `a` is supposed to be
## terminated by `nil`.
if a == nil: return @[]
var L = 0
while a[L] != nil: inc(L)
result = cstringArrayToSeq(a, L)