Subject: Re: [RFC] net,socket: introduce build_sockaddr_check helper to catch overflow at build time

From: Cyrill Gorcunov <[email-masked]>
Date: Sat, 24 Oct 2009 01:43:06 +0400

[Cyrill Gorcunov - Thu, Oct 22, 2009 at 05:55:57PM +0400]
...
| 
| 2) All handlers set *len to some size explicitly so we may
|    introduce set_sockaddr_size() helper like
| 
| #define set_sockaddr_size(ptr, size)		\
| 	do {					\
| 		build_sockaddr_check(size);	\
| 		*ptr = size;			\
| 	} while (0)
| 
| Or you meant something completely different?
| 
| 	-- Cyrill

Or say it could be something like that

#define __sockaddr(type, src)	\
	({ build_sockaddr_check(sizeof(type)); (type *) src; })

and say in function af_inet.c:inet_getname instead of

	struct sockaddr_in *sin	= (struct sockaddr_in *)uaddr;

we may write like

	struct sockaddr_in *sin	= __sockaddr(struct sockaddr_in, uaddr);

which would check the size.

	-- Cyrill