arminbiere / cadical

CaDiCaL SAT Solver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Segfault in Random.cpp (with proposed fix)

sambayless opened this issue · comments

Hi Armin, I recently encountered a segfault when running the mobical tests; the problem only occurred when running mobical without any arguments. Valgrind tracked this down to a null pointer access at Random.cpp:106:

const int family = addr->ifa_addr->sa_family;

Apparently, in some cases, addr->ifa_addr can be null (https://stackoverflow.com/questions/22767155/when-will-ifa-addr-be-null-on-calling-getifaddrs). My machine (Ubuntu 20.04) has a VPN, maybe thats related?

I was able to resolve this by adding a guard to check if addr->ifa_addr is null, eg something like:

 if (!getifaddrs (&addrs)) {
    for (struct ifaddrs * addr = addrs; addr; addr = addr->ifa_next) {
      if (addr->ifa_addr){
          const int family = addr->ifa_addr->sa_family;

Thanks will fix in next minor release.

Now also fixed on main branch and release 1.5.4