Skip to content

Commit

Permalink
files_read_raw_ref: prevent infinite retry loops in general
Browse files Browse the repository at this point in the history
Limit the number of retries to 3. That should be adequate to
prevent any races, while preventing the possibility of
infinite loops if the logic fails to handle any other
possible error modes correctly.

After the fix in the previous commit, there's no known way
to trigger an infinite loop, but I did manually verify that
this fixes the test in that commit even when the code change
is not applied.

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Oct 10, 2016
1 parent 3f7bd76 commit e8c42cb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions refs/files-backend.c
Expand Up @@ -1451,6 +1451,7 @@ int read_raw_ref(const char *refname, unsigned char *sha1,
int fd;
int ret = -1;
int save_errno;
int remaining_retries = 3;

*type = 0;
strbuf_reset(&sb_path);
Expand All @@ -1466,8 +1467,14 @@ int read_raw_ref(const char *refname, unsigned char *sha1,
* <-> symlink) between the lstat() and reading, then
* we don't want to report that as an error but rather
* try again starting with the lstat().
*
* We'll keep a count of the retries, though, just to avoid
* any confusing situation sending us into an infinite loop.
*/

if (remaining_retries-- <= 0)
goto out;

if (lstat(path, &st) < 0) {
if (errno != ENOENT)
goto out;
Expand Down

0 comments on commit e8c42cb

Please sign in to comment.