Fix get_src_for_route_to() when args are NULL

fixes #160 ???
This commit is contained in:
Thomas Bernard 2015-11-16 20:32:02 +01:00
parent 5856fb0f7d
commit 66dceb5e94
2 changed files with 14 additions and 10 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.407 2015/11/05 10:59:33 nanard Exp $
$Id: Changelog.txt,v 1.408 2015/11/16 19:29:42 nanard Exp $
2015/11/16:
Fix bsd/getroute.c get_src_for_route_to() when args are NULL
2015/11/02:
use LOG_INFO instead of LOG_ERR for PCP PEER and MAP success

View File

@ -1,4 +1,4 @@
/* $Id: getroute.c,v 1.4 2014/03/31 12:27:14 nanard Exp $ */
/* $Id: getroute.c,v 1.5 2015/11/16 19:29:50 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard
@ -84,8 +84,7 @@ get_src_for_route_to(const struct sockaddr * dst,
sockaddr_to_string(sa, tmp, sizeof(tmp));
syslog(LOG_DEBUG, "type=%d sa_len=%d sa_family=%d %s",
i, SA_LEN(sa), sa->sa_family, tmp);
if((i == RTA_DST || i == RTA_GATEWAY) &&
(src_len && src)) {
if(i == RTA_DST || i == RTA_GATEWAY) {
size_t len = 0;
void * paddr = NULL;
if(sa->sa_family == AF_INET) {
@ -96,13 +95,15 @@ get_src_for_route_to(const struct sockaddr * dst,
len = sizeof(struct in6_addr);
}
if(paddr) {
if(*src_len < len) {
syslog(LOG_WARNING, "cannot copy src. %u<%u",
(unsigned)*src_len, (unsigned)len);
return -1;
if(src && src_len) {
if(*src_len < len) {
syslog(LOG_WARNING, "cannot copy src. %u<%u",
(unsigned)*src_len, (unsigned)len);
return -1;
}
memcpy(src, paddr, len);
*src_len = len;
}
memcpy(src, paddr, len);
*src_len = len;
found = 1;
}
}