Skip to content

Commit

Permalink
[dhcp6relay] Check interface address is not NULL (#11359)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimmyzhai authored Jul 8, 2022
1 parent 205eb59 commit f788072
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dhcp6relay/src/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void prepare_relay_config(relay_config *interface_config, int *local_sock, int f

ifa_tmp = ifa;
while (ifa_tmp) {
if (ifa_tmp->ifa_addr->sa_family == AF_INET6) {
if (ifa_tmp->ifa_addr && ifa_tmp->ifa_addr->sa_family == AF_INET6) {
struct sockaddr_in6 *in6 = (struct sockaddr_in6*) ifa_tmp->ifa_addr;
if((strcmp(ifa_tmp->ifa_name, interface_config->interface.c_str()) == 0) && !IN6_IS_ADDR_LINKLOCAL(&in6->sin6_addr)) {
non_link_local = *in6;
Expand Down Expand Up @@ -402,7 +402,7 @@ void prepare_socket(int *local_sock, int *server_sock, relay_config *config, int
else {
ifa_tmp = ifa;
while (ifa_tmp) {
if ((ifa_tmp->ifa_addr->sa_family == AF_INET6) && (strcmp(ifa_tmp->ifa_name, config->interface.c_str()) == 0)) {
if (ifa_tmp->ifa_addr && (ifa_tmp->ifa_addr->sa_family == AF_INET6) && (strcmp(ifa_tmp->ifa_name, config->interface.c_str()) == 0)) {
struct sockaddr_in6 *in6 = (struct sockaddr_in6*) ifa_tmp->ifa_addr;
if(!IN6_IS_ADDR_LINKLOCAL(&in6->sin6_addr)) {
bind_addr = true;
Expand Down

0 comments on commit f788072

Please sign in to comment.