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.
This commit is contained in:
Linus Torvalds 2005-05-29 12:06:32 -07:00
Родитель 8b7d510fb1
Коммит b97e3dfa76
1 изменённых файлов: 12 добавлений и 1 удалений

13
mktag.c
Просмотреть файл

@ -106,7 +106,18 @@ int main(int argc, char **argv)
usage("cat <signaturefile> | git-mktag"); usage("cat <signaturefile> | git-mktag");
// Read the signature // Read the signature
size = read(0, buffer, MAXSIZE); size = 0;
for (;;) {
int ret = read(0, buffer + size, MAXSIZE - size);
if (!ret)
break;
if (ret < 0) {
if (errno == EAGAIN)
continue;
break;
}
size += ret;
}
// Verify it for some basic sanity: it needs to start with "object <sha1>\ntype " // Verify it for some basic sanity: it needs to start with "object <sha1>\ntype "
if (verify_tag(buffer, size) < 0) if (verify_tag(buffer, size) < 0)