prototype for socket accept

Paul Whitfield paulw at
Fri Jun 18 00:20:54 UTC 2010

Hello All,

I just helped someone sort out a tricky bug
where they were calling accept.

accept(fd, addr, &address_length);

However, address_length had not been initialised,
so was set to a random value from the stack.
If the address_length was a negative value then
program crashed.

The prototype/code (all versions + in cvs) is

int accept (int s, struct sockaddr *name, int *namelen)

And the code to check that the destination length is

   if (*namelen > nam->m_len)
	*namelen = nam->m_len;
   memcpy (name, mtod(nam, caddr_t), *namelen);

if *namelen is negative, the check fails and
a negative length is passed to memcpy.

Shouldn't the prototype for accept be

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

Thus avoiding this problem?


Message  protected by MailGuard: e-mail anti-virus, anti-spam and content filtering.

More information about the users mailing list