diff options
author | bptato <nincsnevem662@gmail.com> | 2025-03-05 21:37:56 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-03-05 21:38:58 +0100 |
commit | dd522de024f19c864a6929a19a99837002eaaea0 (patch) | |
tree | 14299852ddf077fea9ec62e15e21f927d43df3cb /src | |
parent | fefdacecfc3d46344e7e1d3d8f5a8682f1cdc3a4 (diff) | |
download | chawan-dd522de024f19c864a6929a19a99837002eaaea0.tar.gz |
dynstream: close extraneous fds received
Diffstat (limited to 'src')
-rw-r--r-- | src/io/dynstream.nim | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/io/dynstream.nim b/src/io/dynstream.nim index aa6bf874..89d9dac7 100644 --- a/src/io/dynstream.nim +++ b/src/io/dynstream.nim @@ -379,8 +379,15 @@ proc recvMsg*(s: SocketStream; buffer: var openArray[uint8]; let size = int(cmsg.cmsg_len) - (cast[int](data) - cast[int](cmsg)) if cmsg.cmsg_level == SOL_SOCKET and cmsg.cmsg_type == SCM_RIGHTS and size mod sizeof(cint) == 0: - copyMem(addr fdbuf[numFds], data, size) - numFds += size div sizeof(cint) + let n = size div sizeof(cint) + var m = min(fdbuf.len, numFds + n) - numFds + copyMem(addr fdbuf[numFds], data, m * sizeof(cint)) + numFds += m + while m < n: + var fd {.noinit.}: cint + copyMem(addr fd, addr cast[ptr UncheckedArray[cint]](data)[m], + sizeof(fd)) + discard close(fd) else: #TODO we could just return -2 here, but I'm not sure if it can # ever happen |