On 2011-09-27, at 2:38 PM, Andreas Dilger wrote: > On 2011-09-27, at 1:48 PM, Sergey Poznyakoff wrote: >> Kevin Fox <[email protected]> ha escrit: >> >>> Thats not how I read that function: >>> size_t safe_rw (int fd, void const *buf, size_t count) >>> { >>> enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 }; >>> for (;;) >>> { >>> ssize_t result = rw (fd, buf, count); >>> if (0 <= result) >>> return result; >>> >>> short read, return right away without looping. I don't believe tar >> >> You seem to confuse "short reads" with "interrupted reads". A "short >> read" is when read returns less bytes than requested. No signals are >> delivered it this case. An "interrupted read" occurs when a signal is >> delivered while read is in progress. In that case read returns -1 and >> sets errno to EINTR. That's exactly what this function is designed to >> handle. > > In addition to Kevin's recent comments, I also noticed in the SUSv2 > description of read(2): > > http://pubs.opengroup.org/onlinepubs/007908799/xsh/read.html > > "If the value of nbyte is greater than {SSIZE_MAX}, the result > is implementation-dependent." > > Attached is an (untested) patch for fixing these issues. Maybe > Kevin can give this a spin?
My bad, attached is a better patch (still untested, but fixes a thinko that I'd meant to fix before sending): Cheers, Andreas
safe-short-read.diff
Description: Binary data
