git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Bryan Turner <bturner@atlassian.com>
Cc: "Git Users" <git@vger.kernel.org>, "René Scharfe" <l.s.r@web.de>
Subject: Re: [PATCH 07/18] link_alt_odb_entry: handle normalize_path errors
Date: Mon, 7 Nov 2016 19:30:34 -0500	[thread overview]
Message-ID: <20161108003034.apydvv3bav3s7ehq@sigill.intra.peff.net> (raw)
In-Reply-To: <CAGyf7-HWAMF8S+Bw3wcwJCS1Subc28KHjpSCc1__0qn-GSMyvA@mail.gmail.com>

On Mon, Nov 07, 2016 at 03:42:35PM -0800, Bryan Turner wrote:

> > @@ -335,7 +340,9 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
> >         }
> >
> >         strbuf_add_absolute_path(&objdirbuf, get_object_directory());
> > -       normalize_path_copy(objdirbuf.buf, objdirbuf.buf);
> > +       if (strbuf_normalize_path(&objdirbuf) < 0)
> > +               die("unable to normalize object directory: %s",
> > +                   objdirbuf.buf);
> 
> This appears to break the ability to use a relative alternate via an
> environment variable, since normalize_path_copy_len is explicitly
> documented "Returns failure (non-zero) if a ".." component appears as
> first path"

That shouldn't happen, though, because the path we are normalizing has
been converted to an absolute path via strbuf_add_absolute_path. IOW, if
your relative path is "../../../foo", we should be feeding something
like "/path/to/repo/.git/objects/../../../foo" and normalizing that to
"/path/to/foo".

But in your example, you see:

  error: unable to normalize alternate object path: ../0/objects

which cannot come from the code above, which calls die(). It should be
coming from the call in link_alt_odb_entry().

I think what is happening is that relative paths via environment
variables have always been slightly broken, but happened to mostly work.
In prepare_alt_odb(), we call link_alt_odb_entries() with a NULL
relative_base. That function does two things with it:

  - it may unconditionally dereference it for an error message, which
    would cause a segfault. This is impossible to trigger in practice,
    though, because the error message is related to the depth, which we
    know will always be 0 here.

  - we pass the NULL along to the singular link_alt_odb_entry().
    That function only creates an absolute path if given a non-NULL
    relative_base; otherwise we have always fed the path to
    normalize_path_copy, which is nonsense for a relative path.

    So normalize_path_copy() was _always_ returning an error there, but
    we ignored it and used whatever happened to be left in the buffer
    anyway. And because of the way normalize_path_copy() is implemented,
    that happened to be the untouched original string in most cases. But
    that's mostly an accident. I think it would not be for something
    like "foo/../../bar", which is technically valid (if done from a
    relative base that has at least one path component).

    Moreover, it means we don't have an absolute path to our alternate
    odb. So the path is taken as relative whenever we do an object
    lookup, meaning it will behave differently between a bare repository
    (where we chdir to $GIT_DIR) and one with a working tree (where we
    are generally in the root of the working tree). It can even behave
    differently in the same process if we chdir between object lookups.

So it did happen to work, but I'm not sure it was planned (and obviously
we have no test coverage for it). More on that below.

> Other commits, like [1], suggest the ability to use relative paths in
> alternates is something still actively developed and enhanced. Is it
> intentional that this breaks the ability to use relative alternates?
> If this is to be the "new normal", is there any other option when
> using environment variables besides using absolute paths?

No, I had no intention of disallowing relative alternates (and as you
noticed, a commit from the same series actually expands the use of
relative alternates). My use has been entirely within info/alternates
files, though, not via the environment.

As I said, I'm not sure this was ever meant to work, but as far as I can
tell it mostly _has_ worked, modulo some quirks. So I think we should
consider it a regression for it to stop working in v2.11.

The obvious solution is one of:

  1. Stop calling normalize() at all when we do not have a relative base
     and the path is not absolute. This restores the original quirky
     behavior (plus makes the "foo/../../bar" case work).

     If we want to do the minimum before releasing v2.11, it would be
     that. I'm not sure it leaves things in a very sane state, but at
     least v2.11 does no harm, and anybody who cares can build saner
     semantics for v2.12.

  2. Fix it for real. Pass a real relative_base when linking from the
     environment. The question is: what is the correct relative base? I
     suppose "getcwd() at the time we prepare the alt odb" is
     reasonable, and would behave similarly to older versions ($GIT_DIR
     for bare repos, top of the working tree otherwise).

     If we were designing from scratch, I think saner semantics would
     probably be always relative from $GIT_DIR, or even always relative
     from the object directory (i.e., behave as if the paths were given
     in objects/info/alternates). But that breaks compatibility with
     older versions. If we are treating this as a regression, it is not
     very friendly to say "you are still broken, but you might just need
     to add an extra '..' to your path".

So I dunno. I guess that inclines me towards (1), as it lets us punt on
the harder question.

-Peff

  reply	other threads:[~2016-11-08  0:30 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-03 20:33 [PATCH 0/18] alternate object database cleanups Jeff King
2016-10-03 20:33 ` [PATCH 01/18] t5613: drop reachable_via function Jeff King
2016-10-04  5:48   ` Jacob Keller
2016-10-04 13:43     ` Jeff King
2016-10-03 20:33 ` [PATCH 02/18] t5613: drop test_valid_repo function Jeff King
2016-10-04  5:50   ` Jacob Keller
2016-10-03 20:34 ` [PATCH 03/18] t5613: use test_must_fail Jeff King
2016-10-04  5:51   ` Jacob Keller
2016-10-03 20:34 ` [PATCH 04/18] t5613: whitespace/style cleanups Jeff King
2016-10-04  5:52   ` Jacob Keller
2016-10-04 13:47     ` Jeff King
2016-10-04 20:41       ` Jacob Keller
2016-10-03 20:34 ` [PATCH 05/18] t5613: do not chdir in main process Jeff King
2016-10-04  5:54   ` Jacob Keller
2016-10-04 21:00   ` Junio C Hamano
2016-10-03 20:34 ` [PATCH 06/18] t5613: clarify "too deep" recursion tests Jeff King
2016-10-04  5:57   ` Jacob Keller
2016-10-04 13:48     ` Jeff King
2016-10-04 20:44       ` Jacob Keller
2016-10-04 20:49         ` Jeff King
2016-10-04 20:52           ` Jacob Keller
2016-10-04 20:55             ` Jeff King
2016-10-04 20:58               ` Stefan Beller
2016-10-04 21:00                 ` Jeff King
2016-10-05 13:58                 ` Jakub Narębski
2016-10-05 14:40                   ` Jeff King
2016-10-05 16:14                     ` Junio C Hamano
2016-10-05 16:47                     ` Jacob Keller
2016-10-04 21:43               ` Jacob Keller
2016-10-04 21:49                 ` Jeff King
2016-10-04 21:50                   ` Jacob Keller
2016-10-03 20:34 ` [PATCH 07/18] link_alt_odb_entry: handle normalize_path errors Jeff King
2016-10-04  6:01   ` Jacob Keller
2016-10-04 21:08   ` Junio C Hamano
2016-10-05 18:47   ` René Scharfe
2016-10-05 19:04     ` Jeff King
2016-11-07 23:42   ` Bryan Turner
2016-11-08  0:30     ` Jeff King [this message]
2016-11-08  1:12       ` Bryan Turner
2016-11-08  5:33         ` Jeff King
2016-11-08 19:27           ` Bryan Turner
2016-10-03 20:34 ` [PATCH 08/18] link_alt_odb_entry: refactor string handling Jeff King
2016-10-04  6:05   ` Jacob Keller
2016-10-04 13:53     ` Jeff King
2016-10-04 20:46       ` Jacob Keller
2016-10-04 21:18   ` Junio C Hamano
2016-10-03 20:35 ` [PATCH 09/18] alternates: provide helper for adding to alternates list Jeff King
2016-10-04  6:07   ` Jacob Keller
2016-10-03 20:35 ` [PATCH 10/18] alternates: provide helper for allocating alternate Jeff King
2016-10-04  6:09   ` Jacob Keller
2016-10-03 20:35 ` [PATCH 11/18] alternates: encapsulate alt->base munging Jeff King
2016-10-03 20:35 ` [PATCH 12/18] alternates: use a separate scratch space Jeff King
2016-10-04  6:12   ` Jacob Keller
2016-10-04 21:29   ` Junio C Hamano
2016-10-04 21:32     ` Jeff King
2016-10-04 21:49       ` Junio C Hamano
2016-10-04 21:51         ` Jeff King
2016-10-03 20:35 ` [PATCH 13/18] fill_sha1_file: write "boring" characters Jeff King
2016-10-04  6:13   ` Jacob Keller
2016-10-04 21:46     ` Junio C Hamano
2016-10-04 21:48       ` Jeff King
2016-10-04 21:49       ` Jacob Keller
2016-10-05 19:35         ` Junio C Hamano
2016-10-03 20:36 ` [PATCH 14/18] alternates: store scratch buffer as strbuf Jeff King
2016-10-03 20:36 ` [PATCH 15/18] fill_sha1_file: write into a strbuf Jeff King
2016-10-04  6:44   ` Jacob Keller
2016-10-03 20:36 ` [PATCH 16/18] count-objects: report alternates via verbose mode Jeff King
2016-10-04  6:46   ` Jacob Keller
2016-10-04 13:56     ` Jeff King
2016-10-05 14:23   ` Jakub Narębski
2016-10-05 18:47   ` René Scharfe
2016-10-03 20:36 ` [PATCH 17/18] sha1_file: always allow relative paths to alternates Jeff King
2016-10-04  6:50   ` Jacob Keller
2016-10-04 14:00     ` Jeff King
2016-10-03 20:36 ` [PATCH 18/18] alternates: use fspathcmp to detect duplicates Jeff King
2016-10-04  6:51   ` Jacob Keller
2016-10-04 14:10     ` Jeff King
2016-10-04 21:42   ` Junio C Hamano
2016-10-05  2:34   ` Aaron Schrab
2016-10-05  3:54     ` Jeff King
2016-10-04  5:47 ` [PATCH 0/18] alternate object database cleanups Jacob Keller
2016-10-04 13:41   ` Jeff King
2016-10-04 20:40     ` Jacob Keller
2016-10-05 18:47 ` René Scharfe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161108003034.apydvv3bav3s7ehq@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=bturner@atlassian.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).