You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by rnewson <gi...@git.apache.org> on 2015/09/22 00:39:31 UTC

[GitHub] couchdb-couch pull request: Reject database names with path segmen...

GitHub user rnewson opened a pull request:

    https://github.com/apache/couchdb-couch/pull/102

    Reject database names with path segments over 128 characters

    COUCHDB-2821

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/cloudant/couchdb-couch 2821-dbname-length

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/couchdb-couch/pull/102.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #102
    
----
commit a5acd7ce89e490640e3408e08d287cd5fe39439b
Author: Robert Newson <rn...@apache.org>
Date:   2015-09-21T22:37:33Z

    Reject database names with path segments over 128 characters
    
    COUCHDB-2821

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch pull request: Reject database names with path segmen...

Posted by kxepal <gi...@git.apache.org>.
Github user kxepal commented on the pull request:

    https://github.com/apache/couchdb-couch/pull/102#issuecomment-142202867
  
    Alternative solution:
    
    ```
    diff --git a/src/couch_db.erl b/src/couch_db.erl
    index 6f767d9..877e907 100644
    --- a/src/couch_db.erl
    +++ b/src/couch_db.erl
    @@ -1514,7 +1514,10 @@ validate_dbname(DbName) when is_binary(DbName) ->
     validate_dbname_int(DbName, Normalized) when is_binary(DbName) ->
         case re:run(DbName, ?DBNAME_REGEX, [{capture,none}, dollar_endonly]) of
             match ->
    -            ok;
    +            case validate_part_lengths(DbName) of
    +                ok -> ok;
    +                error -> {error, {database_name_too_long, DbName}}
    +            end;
             nomatch ->
                 case is_systemdb(Normalized) of
                     true -> ok;
    @@ -1522,6 +1525,15 @@ validate_dbname_int(DbName, Normalized) when is_binary(DbName) ->
                 end
         end.
     
    +validate_part_lengths(DbName) when is_binary(DbName)->
    +  validate_part_lengths(filename:split(DbName));
    +validate_part_lengths([]) ->
    +    ok;
    +validate_part_lengths([Part | Rest]) when byte_size(Part) =< 128 ->
    +    validate_part_lengths(Rest);
    +validate_part_lengths([Part | Rest]) when byte_size(Part) > 128 ->
    +    error.
    +
    ```
    
    It makes `validate_dbname_int` looks nice:
    ```
    validate_dbname_int(DbName, Normalized) when is_binary(DbName) ->
        case re:run(DbName, ?DBNAME_REGEX, [{capture,none}, dollar_endonly]) of
            match ->
                case validate_part_lengths(DbName) of
                    ok -> ok;
                    error -> {error, {database_name_too_long, DbName}}
                end;
            nomatch ->
                case is_systemdb(Normalized) of
                    true -> ok;
                    false -> {error, {illegal_database_name, DbName}}
                end
        end.
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch pull request: Reject database names with path segmen...

Posted by kxepal <gi...@git.apache.org>.
Github user kxepal commented on the pull request:

    https://github.com/apache/couchdb-couch/pull/102#issuecomment-142232291
  
    +1 for new version.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch pull request: Reject database names with path segmen...

Posted by kxepal <gi...@git.apache.org>.
Github user kxepal commented on the pull request:

    https://github.com/apache/couchdb-couch/pull/102#issuecomment-142240332
  
    There is a problem with shards:
    ```
    $ http put http://localhost:15984/ebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617ad
    HTTP/1.1 201 Created
    Cache-Control: must-revalidate
    Content-Length: 12
    Content-Type: text/plain; charset=utf-8
    Date: Tue, 22 Sep 2015 10:14:44 GMT
    Location: http://localhost:15984/ebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617ad
    Server: CouchDB/cb58087 (Erlang OTP/18)
    X-Couch-Request-ID: 6f65159f96
    X-CouchDB-Body-Time: 0
    
    {"ok":true}
    
    $ http get http://localhost:15984/ebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617ad
    HTTP/1.1 500 Internal Server Error
    Cache-Control: must-revalidate
    Content-Length: 91
    Content-Type: text/plain; charset=utf-8
    Date: Tue, 22 Sep 2015 10:16:16 GMT
    Server: CouchDB/cb58087 (Erlang OTP/18)
    X-Couch-Request-ID: 757fde0712
    X-Couch-Stack-Hash: 931695309
    X-CouchDB-Body-Time: 0
    
    {"error":"internal_server_error","reason":"No DB shards could be opened.","ref":931695309}
    ```
    
    Obliviously, there are no shards, because:
    ```
    mem3_shards tried to create shards/e0000000-ffffffff/ebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617ad.1442916620, got {error,{database_name_too_long,<<"shards/e0000000-ffffffff/ebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617bbebd6af834f824cff9f8b4ed4bb6617ad.1442916620">>}}
    ```
    
    So technically PR is correct, but not for shards. Revoking my +1. Sorry for missing that case.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch pull request: Reject database names with path segmen...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson closed the pull request at:

    https://github.com/apache/couchdb-couch/pull/102


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch pull request: Reject database names with path segmen...

Posted by kxepal <gi...@git.apache.org>.
Github user kxepal commented on the pull request:

    https://github.com/apache/couchdb-couch/pull/102#issuecomment-142200561
  
    +1


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch pull request: Reject database names with path segmen...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on the pull request:

    https://github.com/apache/couchdb-couch/pull/102#issuecomment-142273038
  
    Replaced by https://github.com/apache/couchdb-fabric/pull/31. I think it makes more sense to ensure the enametoolong error percolates up and prevents the 'dbs' doc being created in the first place. For non-sharded databases, the enametoolong error is already fatal, so nothing needs to happen in couchdb-couch.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---