Why is this not a bug in qmail?

Posted by jemfinch on Stack Overflow See other posts from Stack Overflow or by jemfinch
Published on 2010-04-03T06:11:08Z Indexed on 2010/04/03 6:13 UTC
Read the original article Hit count: 303

Filed under:
|
|

I was reading DJB's "Some thoughts on security after ten years of Qmail 1.0" and he listed this function for moving a file descriptor:

int fd_move(to,from)
int to;
int from;
{
  if (to == from) return 0;
  if (fd_copy(to,from) == -1) return -1;
  close(from);
  return 0;
}

It occurred to me that this code does not check the return value of close, so I read the man page for close(2), and it seems it can fail with EINTR, in which case the appropriate behavior would seem to be to call close again with the same argument.

Since this code was written by someone with far more experience than I in both C and UNIX, and additionally has stood unchanged in qmail for over a decade, I assume there must be some nuance that I'm missing that makes this code correct. Can anyone explain that nuance to me?

© Stack Overflow or respective owner

Related posts about c

    Related posts about unix