git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Bug: bad errno report from lock_ref_sha1_basic() when contents bad
@ 2012-04-02 10:04 Thomas Rast
  2012-04-02 17:30 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Rast @ 2012-04-02 10:04 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

Hi Junio,

User "mbrochh" on IRC reported a result along the lines of

  error: unable to resolve reference refs/remotes/origin/master: Success
  ! [new branch] master -> origin/master (unable to update local ref)

from 'git fetch' (or pull actually, but clearly it's the fetch part
failing).  This error message is from lock_ref_sha1_basic(), and
suggests a confused error exit taken with errno=0.

I can reproduce the problem by writing a bit of garbage to a remote ref
and then fetching, though I usually get some other error in the message
(usually ENOENT, which is equally wrong).

As far as I can tell it's caused by resolve_ref_unsafe() returning NULL
when the content checks fail:

	if (get_sha1_hex(buffer, sha1) || (buffer[40] != '\0' && !isspace(buffer[40]))) {
		if (flag)
			*flag |= REF_ISBROKEN;
		return NULL;
	}

This used to warn before your 5595635 (resolve_ref(): report breakage to
the caller without warning, 2011-10-19), but otherwise suffered from the
same problem.

As far as I can see lock_ref_sha1_basic() needs a similar check for
REF_ISBROKEN (and presumably the only fix is to nuke it so maybe it
should even suggest that to the user).  But in general, the "errno may
be crucial or worthless" interface of lock_ref_sha1_basic() seems a bit
broken...

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug: bad errno report from lock_ref_sha1_basic() when contents bad
  2012-04-02 10:04 Bug: bad errno report from lock_ref_sha1_basic() when contents bad Thomas Rast
@ 2012-04-02 17:30 ` Junio C Hamano
  2012-04-02 18:12   ` Thomas Rast
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2012-04-02 17:30 UTC (permalink / raw)
  To: Thomas Rast; +Cc: git

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

> As far as I can see lock_ref_sha1_basic() needs a similar check for
> REF_ISBROKEN (and presumably the only fix is to nuke it so maybe it
> should even suggest that to the user).

Probably.

> But in general, the "errno may
> be crucial or worthless" interface of lock_ref_sha1_basic() seems a bit
> broken...

Sorry, but I am not sure what you mean by this.  The function is fairly
careful using errno to base its decision and even saves errno when it
calls helpers that may overwrite it, so the "interface" does not want "may
be crucial or worthless".  The implementation may have been broken over
time by many patches, but that is a different issue.  Which codepaths
clobber errno, and is it something you can easily fix with a patch or two?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug: bad errno report from lock_ref_sha1_basic() when contents bad
  2012-04-02 17:30 ` Junio C Hamano
@ 2012-04-02 18:12   ` Thomas Rast
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Rast @ 2012-04-02 18:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Thomas Rast <trast@inf.ethz.ch> writes:
>
>> But in general, the "errno may
>> be crucial or worthless" interface of lock_ref_sha1_basic() seems a bit
>> broken...
>
> Sorry, but I am not sure what you mean by this.  The function is fairly
> careful using errno to base its decision and even saves errno when it
> calls helpers that may overwrite it, so the "interface" does not want "may
> be crucial or worthless".  The implementation may have been broken over
> time by many patches, but that is a different issue.  Which codepaths
> clobber errno, and is it something you can easily fix with a patch or two?

I meant something else, sorry for being so unclear and confused.  In
particular my comment was supposed to be about resolve_ref_unsafe().

It has two different failure modes:

* Some FS syscall went wrong, and errno is crucial for the user to debug
  it (e.g., ENOENT).

* Reading went fine, but we failed to parse the resulting buffer.  errno
  has some unknown value.

The user of the function needs to be aware of this distinction, and
handle it accordingly.  Otherwise it risks emitting outright wrong error
messages, e.g., in my case I got

  thomas@thomas:~/g(next u+107)$ echo garbage >.git/refs/remotes/origin/master
  thomas@thomas:~/g(next u+107)$ g fetch
  error: unable to resolve reference refs/remotes/origin/master: No such file or directory
  From git://git.kernel.org/pub/scm/git/git
   ! [new branch]      master     -> origin/master  (unable to update local ref)

(The IRC user who asked about this was lucky because "Success"
immediately told us that it was an error path not related to syscalls.)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-02 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-02 10:04 Bug: bad errno report from lock_ref_sha1_basic() when contents bad Thomas Rast
2012-04-02 17:30 ` Junio C Hamano
2012-04-02 18:12   ` Thomas Rast

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 NNTP newsgroup(s).