Bug 144231 - bind/connect/sendto too strict about sockaddr length
Summary: bind/connect/sendto too strict about sockaddr length
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 8.0-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-23 14:30 UTC by Axel Dörfler
Modified: 2017-12-31 22:34 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Dörfler 2010-02-23 14:30:01 UTC
bind(), connect(), and sendto() all have a socklen_t argument specifying the size of the sockaddr buffer passed in.

However, with IPv4 at least, passing any other value than 16 (sizeof(sockaddr)) will result in EINVAL.

There is no reason why this restriction is there, and it's quite unhandy when dealing with the sockaddr_storage structure.

(I have not compiled the test program, but it should be able to reproduce the problem)

How-To-Repeat: #include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>

int
main()
{
  sockaddr_storage buffer;
  ((sockaddr_in*)&buffer)->sa_family = AF_INET;
  ((sockaddr_in*)&buffer)->sa_addr.s_addr = INADDR_ANY;
  ((sockaddr_in*)&buffer)->sa_port = 0;

  int fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (bind(fd, &buffer, sizeof(buffer)) != 0)
    perror("bind");

  return 0;
}
Comment 1 Bruce Cran freebsd_committer freebsd_triage 2011-02-17 10:48:57 UTC
Responsible Changed
From-To: freebsd-standards->freebsd-net

Not a standards issue: POSIX says EINVAL is returned if address_len is not a 
valid length for the address family, so FreeBSD's implementation would appear to 
be correct.
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:58:38 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped