Commit 0605801d8523648622fc2176fd0422d3d5a6ad57

Stefan Sperling 2018-03-11T12:44:13

check read() return value properly in read_meta_file()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/lib/worktree.c b/lib/worktree.c
index ae61678..a84d489 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -114,7 +114,8 @@ read_meta_file(char **content, const char *path_got, const char *name)
 
 	n = read(fd, *content, sb.st_size);
 	if (n != sb.st_size) {
-		err = got_error_from_errno();
+		err = (n == -1 ? got_error_from_errno() :
+		    got_error(GOT_ERR_WORKTREE_META));
 		goto done;
 	}
 	if ((*content)[sb.st_size - 1] != '\n') {