summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2012-07-30 12:46:35 +0100
committerRobert Newson <rnewson@apache.org>2012-07-30 12:46:35 +0100
commit09ead8a070050141d8661500fc86e37e1e6a6c9a (patch)
tree6fc4099f142c9695733bdd8f37f5faec691c6df7
parent0e9c5a5afbb35f6fdaa059fa56c6d5ccb87baec9 (diff)
downloadcouchdb-09ead8a070050141d8661500fc86e37e1e6a6c9a.tar.gz
COUCHDB-1512 - Validate bind address
This patch validate the bind_address value before attempting to bind the mochiweb socket, giving an 'invalid_bind_address' error. This should help users who have specified a hostname or made a typo as the original error was less helpful. Fix as suggested by Dave Cottlehuber.
-rw-r--r--src/couchdb/couch_httpd.erl7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 7329c3b4f..9bdc08dc2 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -97,6 +97,7 @@ start_link(Name, Options) ->
% will restart us and then we will pick up the new settings.
BindAddress = couch_config:get("httpd", "bind_address", any),
+ validate_bind_address(BindAddress),
DefaultSpec = "{couch_httpd_db, handle_request}",
DefaultFun = make_arity_1_fun(
couch_config:get("httpd", "default_handler", DefaultSpec)
@@ -1088,4 +1089,8 @@ partial_find(B, D, N, K) ->
partial_find(B, D, 1 + N, K - 1)
end.
-
+validate_bind_address(Address) ->
+ case inet_parse:address(Address) of
+ {ok, _} -> ok;
+ _ -> throw({error, invalid_bind_address})
+ end.