Skip to content

Commit b97e3df

Browse files
author
Linus Torvalds
committed
git-mktag: be more careful in reading the input.
Instead of always assuming it can be read with a single read() system call, loop around properly. Pointed out by Pasky, but I ended up implementing it differently from his suggested patch.
1 parent 8b7d510 commit b97e3df

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

mktag.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,18 @@ int main(int argc, char **argv)
106106
usage("cat <signaturefile> | git-mktag");
107107

108108
// Read the signature
109-
size = read(0, buffer, MAXSIZE);
109+
size = 0;
110+
for (;;) {
111+
int ret = read(0, buffer + size, MAXSIZE - size);
112+
if (!ret)
113+
break;
114+
if (ret < 0) {
115+
if (errno == EAGAIN)
116+
continue;
117+
break;
118+
}
119+
size += ret;
120+
}
110121

111122
// Verify it for some basic sanity: it needs to start with "object <sha1>\ntype "
112123
if (verify_tag(buffer, size) < 0)

0 commit comments

Comments
 (0)