Skip to content

Commit 8e36fb0

Browse files
authored
Update nativesockets.nim, namelen should be the len of name (#24810)
In other places where `getsockname` is called, the size of the 'name' is used. https://github.com/nim-lang/Nim/blob/d573578b28bc4393dac7f3154b5da29b1fa75358/lib/pure/nativesockets.nim#L347-L351 https://github.com/nim-lang/Nim/blob/d573578b28bc4393dac7f3154b5da29b1fa75358/lib/pure/nativesockets.nim#L585-L595 https://github.com/nim-lang/Nim/blob/d573578b28bc4393dac7f3154b5da29b1fa75358/lib/pure/nativesockets.nim#L622-L624 https://github.com/nim-lang/Nim/blob/d573578b28bc4393dac7f3154b5da29b1fa75358/lib/pure/nativesockets.nim#L347-L350 I have checked the [Windows documentation](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockname#remarks), and it describes it like this: "On call, the namelen parameter contains the size of the name buffer, in bytes. On return, the namelen parameter contains the actual size in bytes of the name parameter." [https://www.man7.org/linux/man-pages/man2/getsockname.2.html](https://www.man7.org/linux/man-pages/man2/getsockname.2.html) say: The addrlen argument should be initialized to indicate the amount of space (in bytes) pointed to by addr.
1 parent d573578 commit 8e36fb0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/pure/nativesockets.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ when useNimNetLite:
723723
##
724724
## Similar to POSIX's `getsockname`:idx:.
725725
template sockGetNameOrRaiseError(socket: untyped, name: untyped) =
726-
var namelen = sizeof(socket).SockLen
726+
var namelen = sizeof(name).SockLen
727727
if getsockname(socket, cast[ptr SockAddr](addr(name)),
728728
addr(namelen)) == -1'i32:
729729
raiseOSError(osLastError())

0 commit comments

Comments
 (0)