From 66dceb5e94a6f19cbcef7a037b6628ab8ce446d2 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 16 Nov 2015 20:32:02 +0100 Subject: [PATCH] Fix get_src_for_route_to() when args are NULL fixes #160 ??? --- miniupnpd/Changelog.txt | 5 ++++- miniupnpd/bsd/getroute.c | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index c403d0f..00214f8 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -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 diff --git a/miniupnpd/bsd/getroute.c b/miniupnpd/bsd/getroute.c index e9eda1d..613000d 100644 --- a/miniupnpd/bsd/getroute.c +++ b/miniupnpd/bsd/getroute.c @@ -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; } }