From c1ffba2f957394979da8d30d6b1a2353bf6c825b Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 3 Aug 2008 17:48:11 +0300 Subject: [PATCH] Work around fsp_open_session() not setting errno. fsp_open_session() has a bug where it does not set errno if getaddrinfo fails. Before the bug 1013 fix, this caused an assertion failure. After the bug 1013 fix, this caused a "Success" error message. Now it instead causes "FSP server not found". --- NEWS | 2 +- src/network/state.c | 7 +++++++ src/network/state.h | 2 ++ src/protocol/fsp/fsp.c | 12 +++++++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 954a1f62..74f1019d 100644 --- a/NEWS +++ b/NEWS @@ -21,7 +21,7 @@ includes the changes listed under "ELinks 0.11.4.GIT now" below. JS_CallFunction, which can crash if given a closure. * critical bug 1031: Use the same JSRuntime for both user SMJS and scripts on web pages, to work around SpiderMonkey bug 378918. -* bug 1013: Don't assume errno values are between 0 and 100000 +* bug 1013: Don't assume errno values are between 0 and 100000. * bug 1022: Add connection.ssl.trusted_ca_file setting for GnuTLS. Before this, ELinks did not trust any certificate authorities when it used GnuTLS, so certificate verification always failed if you diff --git a/src/network/state.c b/src/network/state.c index 02f7b174..3a949829 100644 --- a/src/network/state.c +++ b/src/network/state.c @@ -126,6 +126,13 @@ static const struct s_msg_dsc msg_dsc[] = { {S_BITTORRENT_BAD_URL, N_("The BitTorrent URL does not point to a valid URL")}, #endif + /* fsp_open_session() failed but did not set errno. + * fsp_open_session() never sends anything to the FSP server, + * so this error does not mean the server itself does not work. + * More likely, there was some problem in asking a DNS server + * about the address of the FSP server. */ + {S_FSP_OPEN_SESSION_UNKN, N_("FSP server not found")}, + {0, NULL} }; diff --git a/src/network/state.h b/src/network/state.h index d139d092..16faf418 100644 --- a/src/network/state.h +++ b/src/network/state.h @@ -103,6 +103,8 @@ enum connection_basic_state { S_BITTORRENT_METAINFO = -100801, S_BITTORRENT_TRACKER = -100802, S_BITTORRENT_BAD_URL = -100803, + + S_FSP_OPEN_SESSION_UNKN = -100900, }; /** Either an ELinks internal status code or an error code from the diff --git a/src/protocol/fsp/fsp.c b/src/protocol/fsp/fsp.c index a46cc8d3..4479f5ba 100644 --- a/src/protocol/fsp/fsp.c +++ b/src/protocol/fsp/fsp.c @@ -277,8 +277,18 @@ do_fsp(struct connection *conn) if (auth) password = auth->password; } + /* fsp_open_session may not set errno if getaddrinfo fails + * https://sourceforge.net/tracker/index.php?func=detail&aid=2036798&group_id=93841&atid=605738 + * Try to detect this bug and use an ELinks-specific error + * code instead, so that we can display a message anyway. */ + errno = 0; ses = fsp_open_session(host, port, password); - if (!ses) fsp_error(connection_state_for_errno(errno)); + if (!ses) { + if (errno) + fsp_error(connection_state_for_errno(errno)); + else + fsp_error(connection_state(S_FSP_OPEN_SESSION_UNKN)); + } /* fsplib 0.8 ABI depends on _FILE_OFFSET_BITS * https://sourceforge.net/tracker/index.php?func=detail&aid=1674729&group_id=93841&atid=605738 -- 2.11.4.GIT