diff options
| author | F. Aragon <paco@voltanet.io> | 2018-07-03 20:07:25 +0200 | 
|---|---|---|
| committer | F. Aragon <paco@voltanet.io> | 2018-07-04 00:01:22 +0200 | 
| commit | 4149ef7c0f0876a2b9fdfe34afc1ecd9036b2382 (patch) | |
| tree | 22341ea9b9bcd5bb71483cf5559f7906233690d5 /ldpd/util.c | |
| parent | 7f04893904881c2822a3736d004358a0dad9f959 (diff) | |
ldpd: buffer underflow, thread safety (PVS-Studio)
This commit fixes two issues:
- memcpy() using containers of different sizes when using addr2sa(), mixing
  'struct sockaddr_storage' and 'union sockunion'.
- addr2sa() function not being thread safe (using a local static variable as
  container.
Signed-off-by: F. Aragon <paco@voltanet.io>
Diffstat (limited to 'ldpd/util.c')
| -rw-r--r-- | ldpd/util.c | 13 | 
1 files changed, 5 insertions, 8 deletions
diff --git a/ldpd/util.c b/ldpd/util.c index e735263f5f..12f9cb0ccf 100644 --- a/ldpd/util.c +++ b/ldpd/util.c @@ -305,14 +305,13 @@ clearscope(struct in6_addr *in6)  	}  } -struct sockaddr * -addr2sa(int af, union ldpd_addr *addr, uint16_t port) +void +addr2sa(int af, const union ldpd_addr *addr, uint16_t port, union sockunion *su)  { -	static struct sockaddr_storage	 ss; -	struct sockaddr_in		*sa_in = (struct sockaddr_in *)&ss; -	struct sockaddr_in6		*sa_in6 = (struct sockaddr_in6 *)&ss; +	struct sockaddr_in		*sa_in = &su->sin; +	struct sockaddr_in6		*sa_in6 = &su->sin6; -	memset(&ss, 0, sizeof(ss)); +	memset(su, 0, sizeof(*su));  	switch (af) {  	case AF_INET:  		sa_in->sin_family = AF_INET; @@ -333,8 +332,6 @@ addr2sa(int af, union ldpd_addr *addr, uint16_t port)  	default:  		fatalx("addr2sa: unknown af");  	} - -	return ((struct sockaddr *)&ss);  }  void  | 
