Skip to content

Commit 599d223

Browse files
peffgitster
authored andcommitted
sha1fd_check: die when we cannot open the file
Right now we return a NULL "struct sha1file" if we encounter an error. However, the sole caller (write_idx_file) does not check the return value, and will segfault if we hit this case. One option would be to handle the error in the caller. However, there's really nothing for it to do but die. This code path is hit during "git index-pack --verify"; after we verify the packfile, we check that the ".idx" we would generate from it is byte-wise identical to what is on disk. We hit the error (and segfault) if we can't open the .idx file (a likely cause of this is that somebody else ran "git repack -ad" while we were verifying). Since we can't complete the requested verification, we really have no choice but to die. Furthermore, the rest of the sha1fd_* functions simply die on errors. So if were to open the file successfully, for example, and then hit a read error, sha1write would call die() for us. So pushing the die() down into sha1fd_check keeps the interface consistent. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 282616c commit 599d223

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

csum-file.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,10 @@ struct sha1file *sha1fd_check(const char *name)
130130

131131
sink = open("/dev/null", O_WRONLY);
132132
if (sink < 0)
133-
return NULL;
133+
die_errno("unable to open /dev/null");
134134
check = open(name, O_RDONLY);
135-
if (check < 0) {
136-
int saved_errno = errno;
137-
close(sink);
138-
errno = saved_errno;
139-
return NULL;
140-
}
135+
if (check < 0)
136+
die_errno("unable to open '%s'", name);
141137
f = sha1fd(sink, name);
142138
f->check_fd = check;
143139
return f;

0 commit comments

Comments
 (0)