iilyak closed pull request #1647: Validate database prefix against DBNAME_REGEX
for system dbs
URL: https://github.com/apache/couchdb/pull/1647
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 55664e9649..4d76ceedcb 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -1738,8 +1738,15 @@ validate_dbname_int(DbName, Normalized) when
is_binary(DbName) ->
is_systemdb(DbName) when is_list(DbName) ->
is_systemdb(?l2b(DbName));
is_systemdb(DbName) when is_binary(DbName) ->
- lists:member(dbname_suffix(DbName), ?SYSTEM_DATABASES).
-
+ Normalized = normalize_dbname(DbName),
+ Suffix = filename:basename(Normalized),
+ case {filename:dirname(Normalized), lists:member(Suffix,
?SYSTEM_DATABASES)} of
+ {<<".">>, Result} -> Result;
+ {Prefix, false} -> false;
+ {Prefix, true} ->
+ ReOpts = [{capture,none}, dollar_endonly],
+ re:run(Prefix, ?DBNAME_REGEX, ReOpts) == match
+ end.
set_design_doc_keys(Options1) ->
Dir = case lists:keyfind(dir, 1, Options1) of
@@ -1831,7 +1838,9 @@ validate_dbname_fail_test_() ->
Cases = generate_cases("_long/co$mplex-/path+/_something")
++ generate_cases("_something")
++ generate_cases_with_shards("long/co$mplex-/path+/_something#")
- ++ generate_cases_with_shards("long/co$mplex-/path+/some.thing"),
+ ++ generate_cases_with_shards("long/co$mplex-/path+/some.thing")
+ ++ generate_cases("!abcdefg/werwej/_users")
+ ++ generate_cases_with_shards("!abcdefg/werwej/_users"),
{
foreach, fun setup/0, fun teardown/1,
[should_fail_validate_dbname(A) || {_, A} <- Cases]
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services