eggdrop icon indicating copy to clipboard operation
eggdrop copied to clipboard

Avoid freeaddrinfo(NULL) and enhance error logging

Open michaelortmann opened this issue 2 years ago • 1 comments

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)

michaelortmann avatar Sep 13 '22 22:09 michaelortmann

lgtm

thommey avatar Sep 20 '22 15:09 thommey

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)

vanosg avatar Sep 27 '22 01:09 vanosg

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.

michaelortmann avatar Sep 28 '22 01:09 michaelortmann

.tcl listen foo.com 4444
Tcl error: invalid ip address

vanosg avatar Oct 01 '22 14:10 vanosg

What do you think of that?

vanosg avatar Oct 01 '22 14:10 vanosg