Thomas Rast <tr...@inf.ethz.ch> writes:

> From a cursory glance it looks like it's actually an existing bug in
> read_revisions_from_stdin or handle_revision_arg, depending on which way
> you look at it.  read_revisions_from_stdin passes its temporary buffer
> down to handle_revision_arg:
>
>         struct strbuf sb;
>         [...]
>         strbuf_init(&sb, 1000);
>         while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
>                 [...]
>                 if (handle_revision_arg(sb.buf, revs, 0, 
> REVARG_CANNOT_BE_FILENAME))
>                         die("bad revision '%s'", sb.buf);
>         }
>
> But handle_revision_arg ends up just stuffing that parameter into the
> revision-walker options via some helpers:
>
>       add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags);
>       add_pending_object_with_mode(revs, object, arg, oc.mode);
>
> This seems to have been lurking since 281eee4 (revision: keep track of
> the end-user input from the command line, 2011-08-25).
>
> Junio, at which level should we fix it?  We could of course have
> read_revisions_from_stdin make a copy of the buffers it passes down, but
> perhaps it would be less surprising to instead have handle_revision_arg
> make sure it makes a copy of everything it "keeps"?

Looking at it again, it seems that the issue is much older than the
introduction of cmdline interface.

Everything we throw at add_pending_object() is assumed to be stable,
because historically they were argv[] strings, and --stdin is what
breaks that assumption.  Making copies unconditionally at the lower
layer only because some minority callers give it unstable strings
does not sound like a good trade-off.

So I changed my mind.  Your "easy fix" looks to me the right thing
to do.

The paths given to handle_refs() may also have to be copied before
saved, depending on how ref iteration is implemented, details of
which may change as Michael seems to be updating the area again.
I think we let the callback peek ref_entry->name[] which is stable,
so I suspect we are OK.

> The easy fix of course is just this:
>
> diff --git i/revision.c w/revision.c
> index 3a20c96..181a8db 100644
> --- i/revision.c
> +++ w/revision.c
> @@ -1277,7 +1277,8 @@ static void read_revisions_from_stdin(struct rev_info 
> *revs,
>                       }
>                       die("options not supported in --stdin mode");
>               }
> -             if (handle_revision_arg(sb.buf, revs, 0, 
> REVARG_CANNOT_BE_FILENAME))
> +             if (handle_revision_arg(xstrdup(sb.buf), revs, 0,
> +                                     REVARG_CANNOT_BE_FILENAME))
>                       die("bad revision '%s'", sb.buf);
>       }
>       if (seen_dashdash)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to