eggdrop
eggdrop copied to clipboard
Avoid freeaddrinfo(NULL) and enhance error logging
Found by: michaelortmann Patch by: Release_ Fixes: #1329
One-line summary:
Avoid freeaddrinfo(NULL)
and enhance error logging
Additional description (if needed):
The behavior of freeadrinfo(NULL)
is left unspecified by RFC 3493
Some Operating Systems like FreeBSD handle this for compatibility / portability but others like OpenBSD do not (as reported in #1329), so let eggdrop avoid calling freeadrinfo(NULL)
.
Log gai_strerror()
for every single case of error of getaddrinfo()
and getnameinfo()
Test cases demonstrating functionality (if applicable):
$ uname -a
OpenBSD openbsd71.home.arpa 7.1 GENERIC.MP#3 amd64
Config file:
set listen-addr test.com
listen 3333 all
Before:
* Last context: tclhash.c/247 []
* Please REPORT this BUG!
* Check doc/BUG-REPORT on how to do so.
* Wrote DEBUG
* SEGMENT VIOLATION -- CRASHING!
Segmentation fault (core dumped)
After:
tcldcc: setlisten(): getaddrinfo(): hostname 'test.com' not known
Tcl error in file 'BotA.conf':
Couldn't listen on port '3333' on the given address: Cannot assign requested address. Please check that the port is not already in use
while executing
"listen 3333 all"
(file "BotA.conf" line 1668)
* CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
lgtm
Putting aside the "should we allow hostnames" (probably yes, just not for this version)- can we change the error message to something more like "unknown IP address" instead of "unknown hostname"? I think an error like this would lead the user to believe there is something wrong with the hostname provided, instead of telling them hostnames are not allowed.
(that is, if I'm reading that error case for EAI_NONAME correctly, I can't fully tell from a quick glance if it is also for an unresolvable hostname)
EAI_NONAME is not exactly identical for unresolveable i suppose. but the man pages combined with apriori knowledge about our usage of the function getaddrinfo() we are fine logging like this. the alternative would be to not handle EAI_NONAME as any special case and print system default error for it, which is more generic but has less power to help the user for our use case.
.tcl listen foo.com 4444
Tcl error: invalid ip address
What do you think of that?