Skip to content

Commit 9991b6a

Browse files
jimmyzhaiqiluo-msft
authored andcommitted
[dhcp6relay] Check interface address is not NULL (sonic-net#11359)
Why I did it Daemon dhcp6relay may crash due to null pointer access to ifa_addr member of struct ifaddrs. It's not guaranteed that the interface must have available ifa_addr. That is true for some special virtual/pseudo interfaces. How I did it Check the pointer to ifa_addr is valid ahead of accessing it.
1 parent de786cc commit 9991b6a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/dhcp6relay/src/relay.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void prepare_relay_config(relay_config *interface_config, int *local_sock, int f
344344

345345
ifa_tmp = ifa;
346346
while (ifa_tmp) {
347-
if (ifa_tmp->ifa_addr->sa_family == AF_INET6) {
347+
if (ifa_tmp->ifa_addr && ifa_tmp->ifa_addr->sa_family == AF_INET6) {
348348
struct sockaddr_in6 *in6 = (struct sockaddr_in6*) ifa_tmp->ifa_addr;
349349
if((strcmp(ifa_tmp->ifa_name, interface_config->interface.c_str()) == 0) && !IN6_IS_ADDR_LINKLOCAL(&in6->sin6_addr)) {
350350
non_link_local = *in6;
@@ -402,7 +402,7 @@ void prepare_socket(int *local_sock, int *server_sock, relay_config *config, int
402402
else {
403403
ifa_tmp = ifa;
404404
while (ifa_tmp) {
405-
if ((ifa_tmp->ifa_addr->sa_family == AF_INET6) && (strcmp(ifa_tmp->ifa_name, config->interface.c_str()) == 0)) {
405+
if (ifa_tmp->ifa_addr && (ifa_tmp->ifa_addr->sa_family == AF_INET6) && (strcmp(ifa_tmp->ifa_name, config->interface.c_str()) == 0)) {
406406
struct sockaddr_in6 *in6 = (struct sockaddr_in6*) ifa_tmp->ifa_addr;
407407
if(!IN6_IS_ADDR_LINKLOCAL(&in6->sin6_addr)) {
408408
bind_addr = true;

0 commit comments

Comments
 (0)