diff options
author | Patrick Steinhardt <ps@pks.im> | 2016-03-10 17:05:30 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2016-03-11 14:20:15 +0100 |
commit | 6ff8a7c4bed65f8fd7d7fbda662583499e68e2aa (patch) | |
tree | 7005f40ab24e35b59ca960c115be281c0216f3a0 | |
parent | 836447e586f275a1f0b32860805f69ad6867ec32 (diff) | |
download | libgit2-6ff8a7c4bed65f8fd7d7fbda662583499e68e2aa.tar.gz |
filebuf: handle write error in `lock_file`
When writing to a file with locking not check if writing the
locked file actually succeeds. Fix the issue by returning error
code and message when writing fails.
-rw-r--r-- | src/filebuf.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/filebuf.c b/src/filebuf.c index 17efe872e..101d5082a 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -70,6 +70,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) git_file source; char buffer[FILEIO_BUFSIZE]; ssize_t read_bytes; + int error; source = p_open(file->path_original, O_RDONLY); if (source < 0) { @@ -80,7 +81,8 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) } while ((read_bytes = p_read(source, buffer, sizeof(buffer))) > 0) { - p_write(file->fd, buffer, read_bytes); + if ((error = p_write(file->fd, buffer, read_bytes)) < 0) + break; if (file->compute_digest) git_hash_update(&file->digest, buffer, read_bytes); } @@ -90,6 +92,9 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) if (read_bytes < 0) { giterr_set(GITERR_OS, "Failed to read file '%s'", file->path_original); return -1; + } else if (error < 0) { + giterr_set(GITERR_OS, "Failed to write file '%s'", file->path_lock); + return -1; } } |