Permalink
Browse files

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.
  • Loading branch information...
1 parent 0e9c5a5 commit 09ead8a070050141d8661500fc86e37e1e6a6c9a @rnewson rnewson committed Jul 30, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 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.

0 comments on commit 09ead8a

Please sign in to comment.