Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAddrInfo index out of bounds error #10198

Closed
FedericoCeratto opened this issue Jan 4, 2019 · 3 comments

Comments

Projects
None yet
4 participants
@FedericoCeratto
Copy link
Member

commented Jan 4, 2019

sendTo() fails on a raw ICMP socket:

import net
newSocket(AF_INET, SOCK_RAW, IPPROTO_ICMP).sendTo("127.0.0.1", 0.Port, "")    

getAddrInfo in nativesockets.nim raises:

Error: unhandled exception: index out of bounds: (i:-1) <= (n:-1)  [IndexError]
@BontaVlad

This comment has been minimized.

Copy link

commented Jan 5, 2019

Since this could be my first ever PR for a open source project I will leave a comment here first.
I managed to fix this issue by adding a check in nativesockets.nim:getAddrInfo

let socket_port = if sockType == SOCK_RAW: "" else: $port
var gaiResult = getaddrinfo(address, socket_port, addr(hints), result)

SOCK_RAW (a socket type that does not support the concept of services)
More info can be found here
If there are more socket types that don't need a 'port' let me know.

I also changed 2 lines of code in oserr.nim:

  + if e.msg == "":
  +  e.msg = "unknown OS error"
  if additionalInfo.len > 0:
    if e.msg[^1] != '\n': e.msg.add '\n'
    e.msg.add  "Additional info: "
    e.msg.addQuoted additionalInfo
  - if e.msg == "":
  -  e.msg = "unknown OS error"

This will make raiseOSError care about additionalInfo even for errors that could not be retrieved, in the getAddrInfo example, useful error msg like gai_strerror(gaiResult) would never be shown.
Let me know if I misunderstood something. I also have could submit a PR if this is desired.

@FedericoCeratto

This comment has been minimized.

Copy link
Member Author

commented Jan 5, 2019

@BontaVlad thanks, I successfully tested the change to getAddrInfo. I can add a test under tests/stdlib in your PR

FedericoCeratto added a commit to FedericoCeratto/Nim that referenced this issue Jan 5, 2019

@FedericoCeratto

This comment has been minimized.

Copy link
Member Author

commented Jan 5, 2019

I opened PR #10210 to also add ICMPv6 - I hope you don't mind.

FedericoCeratto added a commit to FedericoCeratto/Nim that referenced this issue Jan 6, 2019

@dom96 dom96 closed this in 2fa3512 Jan 6, 2019

@narimiran narimiran referenced this issue Jan 7, 2019

Closed

Fixes 9880 #10228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.